Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabling Drupal's CSS/JS aggregation for admins

Tags:

drupal

Drupal 6 has a wonderful CSS and JavaScript aggregator. Unfortunately, it interferes with development as it's only regenerated when you clear the Drupal cache.

I'd like to turn it on for non-admins (to save HTTP requests) but have the individual CSS and JS files served directly to admins for development. Has anyone done this? Is it possible?

like image 791
ceejayoz Avatar asked Sep 03 '09 20:09

ceejayoz


1 Answers

That's an interesting idea. Since the aggregation settings are stored in Drupal variables, and those are read into the global $conf array during bootstrapping, I tried the following in a modules hook_init() implementation:

global $user;
if (1 == $user->uid) {
  global $conf;
  $conf['preprocess_css'] = FALSE;
  $conf['preprocess_js'] = FALSE;
}

So far this just works :)

Now I'm suspicious - according to my standard experience over the years, if something is that simple on first sight, it will break down horribly sooner or later ;)

But right now the worst thing I can imagine happening with this is that it just fails in situations where for some reason or the other the $conf array gets repopulated during a page cycle, in which case the admin would just get the cached versions again.

like image 170
Henrik Opel Avatar answered Oct 16 '22 22:10

Henrik Opel