2

When working in a dev environment with performance caching and aggregation turned off is there a standard way to prevent the cache clear hash from being appended to CSS/JS file names?

I'd like to avoiding hooking into the output and removing this manually in a dev only module.

6
  • Just as a side comment, the hash is actually a feature that will update itself automatically when there has been a change to one of the files. This tells the browser to re-download the CSS/JS files instead of using its internal cached version. Pretty important for ever-changing sites. Commented Jun 8, 2012 at 21:22
  • NOTE: "dev environment". Also the hash doesn't update with a file change, it's on cache clear. This is a major annoyance on development env. You should be aggregating your files on production. The hash feature is actually pretty useless since that mode should never be used except of dev anyway. Plus, it's not reliable in all browsers. Bad choice in Drupal, but I suppose it's for the small sites that don't turn on aggregation.
    – doublejosh
    Commented Jun 8, 2012 at 21:52
  • You're right, it only changes on cache clear. But for clarification, what problem comes about from the hash? Commented Jun 11, 2012 at 14:00
  • While developing locally you can't see your file changes when refreshing your browser... I certainly don't want to clear cache for every few lines of CSS/JS I update.
    – doublejosh
    Commented Jun 26, 2012 at 19:16
  • With or without the hash, you will not see any CSS or JS changes unless you do a Force Refresh in your browser. My point was simply that the hash does not create a problem. The problem is there with or without the hash. Commented Jun 26, 2012 at 19:42

1 Answer 1

2

Here's the solution (theme based) in template.php

function MYTHEME_process_html(&$vars) {
  if (variable_get('environment') == 'development' && !stristr($_GET['q'],'flush-cache')) {
    $vars['styles'] = preg_replace('/\.css\?.*"/','.css"', $vars['styles']);
  }
}

NOTE: This assume you have an environment setting in your settings.local.php file like so... $conf['environment'] = 'development'; or $conf['environment'] = 'production';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.