Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I created a sub theme which add's a Dev option to temporary disable Drupal's CacheBuster query strings after the stylesheet file name (style.css?XYZ). This is useful for live styling with Espresso or CSSEdit for Mac using their great @override feature.
Mabe it could be included in Zentropy core.
theme-settings.php
$form['zentropy_settings']['zentropy_dev']['zentropy_cachebuster_css'] = array(
'#type' => 'select',
'#title' => t('CachBuster CSS query strings'),
'#description' => t('During theme styling with CSSEdit’s or Espresso’s @override feature, it can be very useful to disable the CacheBuster CSS query strings. (style.css?XYZ)'),
'#default_value' => theme_get_setting('zentropy_cachebuster_css'),
'#options' => array(
'' => t('Add query strings (Drupal default)'),
'all' => t('Always remove query strings'),
'onlyadmin' => t('Remove query strings for logged in admins only'),
),
);
template.php
/**
* Implements template_process_html().
*/
// Remove Query Strings from CSS filenames (CacheBuster)
function zentropy_process_html(&$variables) {
global $user, $conf;
if (theme_get_setting('zentropy_cachebuster_css')) {
if (theme_get_setting('zentropy_cachebuster_css') == 'all' || (in_array("administrator",$user->roles) && @$conf['site_offline'] == 0 && !stristr($_GET['q'],'flush-cache'))) {
$variables['styles'] = preg_replace('/\.css\?.*"/','.css"', $variables['styles']);
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#2 | zentropy-cachebuster-1462572-2.patch | 2.18 KB | Wolfgang Reszel |
Comments
Comment #1
alexweber CreditAttribution: alexweber commentedAwesome! Absolutely!
Would you mind creating a patch against 7.x-2.0-dev?
I would happily review and commit it, giving you author credits! :)
Comment #2
Wolfgang Reszel CreditAttribution: Wolfgang Reszel commentedOkay. I try. I never created a patch before. I hope it works.
Comment #3
alexweber CreditAttribution: alexweber commentedPatch applied cleanly, commited in 457ded5.
Thanks! :)
Comment #4
alexweber CreditAttribution: alexweber commentedWolfgang, I've been thinking about this and I love the feature but I don't see why we need to have the option to enable it for admins only. Since this is a development-only feature we assume that performance doesn't matter, I'm going to change this to either on or off.
Comments?
Comment #5
Wolfgang Reszel CreditAttribution: Wolfgang Reszel commentedWell, my Drupal projects are often vital projects where I sometimes adjust or enhance the styling on the page which is already online. I don't want the visitors or editors would be forced to reload the stylesheets. So I just have to login as admin for styling without affecting other users and its also faster than enabling this option every time I need it. Previously I had this always hardcoded in my templates and as I decided to always use Zentropy as my base for future projects I thought it would be cool to be optional. Sometimes I need styling when not logged in, so a simple on-off does not fit my needs.
Comment #6
alexweber CreditAttribution: alexweber commentedWolfgang, I understand and will take this into consideration!
PS - The commit is looking nice in your profile page! ;)
Comment #7
alexweber CreditAttribution: alexweber commented@Wolfgang, I gave this some thought and re-enabled the "admin only" option. Commited in dev, release coming later on tonight! :)
Comment #8
doublejosh CreditAttribution: doublejosh commentedLovely.
This is a nice general solution as well.
As long as you place these in your settings.local.php files...
$conf['environment'] = 'development';
$conf['environment'] = 'production';
Comment #8.0
doublejosh CreditAttribution: doublejosh commentedTypo