Skip to content

Instantly share code, notes, and snippets.

@flashvnn
Created May 7, 2014 04:34
Show Gist options
  • Save flashvnn/5b036bed25c15647d622 to your computer and use it in GitHub Desktop.
Save flashvnn/5b036bed25c15647d622 to your computer and use it in GitHub Desktop.
Remove query strings from static resources drupal
<?php
/**
* Implements template_process_html().
*/
// Remove Query Strings from CSS filenames (CacheBuster)
function MYTHEME_process_html(&$variables) {
$variables['styles'] = preg_replace('/\.css\?.*"/','.css"', $variables['styles']);
}
?>
@charlesroper
Copy link

Very handy! The regex is greedy, though, which means it it keeps matching until the last quote it can find. Here's what I changed it to:

$variables['styles'] = preg_replace('/\.css\?[^"]+/','.css', $variables['styles']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment