Disable Cache Before developing Drupal Theme

Drupal 8 Theme Developer

I recently started developing Drupal 8 theme. But every time I was making any change, I had to clear Drupal cache. So, here is how you can disable Drupal cache when developing theme / module for Drupal 8 and 9.

Step #1: Disable Aggregation

Navigate to:
Home arrow-icon Administration arrow-icon Configuration arrow-icon Development arrow-icon Performance

  • Uncheck Aggregate CSS files.
  • Uncheck Aggregate JavaScript files.

and save configuration. You should also clear all caches.

disable-aggregation

Step #2: Create local settings file

Copy and rename /sites/example.settings.local.php to be /sites/default/settings.local.php

Step #3: Enable local settings file

Open /sites/default/settings.php file and uncomment (remove # sign from beginning) these lines:

settings.php file may have read only permission. So, change its permission before editing. And after editing this file, revert back file permission to the original.
if (file_exists(__DIR__ . '/settings.local.php')) {
   include __DIR__ . '/settings.local.php';
}

And add this line at the bottom. Save and close settings.php file.

$settings['cache']['bins']['page'] = 'cache.backend.null';

Step #4

Uncomment (remove # sign from the beginning) these lines in /sites/default/settings.local.php to disable the render cache and disable dynamic page cache:

$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

Step #5

Find and un-comment below line in /sites/default/settings.local.php

$settings['cache']['bins']['page'] = 'cache.backend.null';

Step #6

Open /sites/development.services.yml. Delete previous codes and paste below codes.

# Local development services.
#
# To activate this feature, follow the instructions at the top of the
# 'example.settings.local.php' file, which sits next to this file.
parameters:
  http.response.debug_cacheability_headers: true
  twig.config:
    debug: true
    auto_reload: true
    cache: false
services:
  cache.backend.null:
    class: Drupal\Core\Cache\NullBackendFactory

Step #7: Rebuild

Rebuild Drupal cache by visitng following url.

example.com/core/rebuild.php

Done!!

Comments

user
Submitted by tamkinlinks on Fri, 10/21/2016 - 17:23

good