Drupal — disable CSS cache

2019-02-17 05:10发布

问题:

I am using Drupal 6. Every time I modify the CSS files, I need to clear the cache to see the updated result, which is a waste of my time. Is there any way to disable the cache system?

回答1:

The reason the CSS cache needs refreshing is because Drupal optimizes all individual CSS files from various modules and themes into one CSS file which is optimized into a single file.

So that this file is not recompiled every page load, which would loose the benefit of optimization, Drupal needs to know when the CSS file has changed in order to recompile this. At which cache refresh seems like the ideal time. To turn this off - rather than turn off caching completely you can simply:

Go to /admin/settings/performance where there is a field labeled "Optimize CSS files":

Disable this whilst you are doing your development and making changes to your CSS file. Then when in production and most of your CSS is set then you can enable it. I highly recommend the performance gains this brings in the loading of your pages.

I have the administration menu module installed, and it is very easy to empty the cache from here in a single click - have a try...



回答2:

Also, for the purpose of development you could place the following in your template.php (assuming you're working on a theme).

drupal_flush_all_caches();

See http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_flush_all_caches/6



回答3:

Have a look at Disabling the Drupal cache. That should get you going in the right direction.



回答4:

It’s advisable to use CSS cache for Drupal optimization. To check your changes in CSS simply go to “admin/settings/performance” in Drupal 6 and "admin/config/development/performance" in Drupal 7 and disable “Optimize CSS files" in Drupal 6 and “Aggregate and compress CSS files" in Drupal 7 instead of turning off caching completely.



回答5:

This approach is version agnostic. The code in this example is for Drupal 7.

Step 1: @include a template preprocess file at the beginning of your template file. (if present). This file is not added to the repository (ignored for version control (Git)), so it is not distributed across environments and each dev can have its own actions and settings in this file.

Step 2: In this file, do your local template preprocess stuff like:

Additionally, you can flush all your caches for DEV only.



回答6:

For Drupal 7 just add this to settings.php:

$conf['page_compression'] = 0;
$conf['preprocess_js'] = 0;
$conf['preprocess_css'] = 0;

It will override the current settings on "Performance" (admin/config/development/performance), and if you delete the above lines you will see the original configuration after clean cache.



标签: drupal