Private files and CSS/JS Aggregation

TM
TM's picture
Joined: 04/24/2009

Hello all,

I've been up and down the Drupal site for a solution and haven't found any viable solutions other than hacking the core files. Here's the deal: I'm using Drupal 6. I've got the Download method (admin/settings/file-system) set to Private. This is because I need special permissions for some uploaded files; it can't all be available to everyone. I'd really like to be able to use the CSS/JavaScript aggregation feature (admin/settings/performance) but it doesn't work with the Private download method (the option is grayed out).

Does anyone know how to do CSS/JS aggregation in Private download mode? I do know that Drupal 7 (but I'm not waiting for that) is addressing this, and I have seen the following posts already
http://drupal.org/node/254780 ("Doing CSS aggregation in your theme")
http://drupal.org/node/296831 ("Enabling css/js aggregation, color module and/or JavaScript translations for the private download method")

With the first link, has anyone tried this? Does it work? Can we tweak to do JS, too? What's the downside? I would imagine there's a performance hit, and it looks like it generates a CSS for each page. Is that right?

The second link is a hack. Doing this really isn't a good option because a) it's a hack (!), and b) you have to re-apply the patch every time you upgrade, and I don't want to have to do this across multiple sites every couple months.

I was thinking of maybe making a custom module that simply generates aggregated JS and CSS file and names it whatever you want. Then I would just hard-code those filenames into my theme (or use the variable system). I would just run that module whenever there's a CSS/JS change, which should be very seldom. But I'm not quite if that would work, or how to go about it.

Thoughts??

Blessings
Tom

Therefore, as you received Christ Jesus the Lord, so walk in Him, rooted and built up in Him and established in the faith, just as you were taught, abounding in thanksgiving. (Col 2:6-7)

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
A custom module

I would take the custom module approach. It's actually fairly straight forward (says the guy who has worked on that part of drupals code extensively).

Drupal 7 has already addressed this. You can now have private and public files separate from each other (thank you stream wrappers).

Take a look at the functions drupal_get_js and drupal_get_css on http://api.drupal.org. In there you'll find the guts of the code to make this happen.

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

TM
TM's picture
Joined: 04/24/2009
Good start

Thanks, Matt. This doesn't cause performance issues, does it? I was reading somewhere (I think) that some approach like this re-bootstrapped Drupal, but maybe that was just that one approach.

So you think the custom module is the way to go..... do you agree with the approach to run this new aggregator module manually only when the CSS's are updated and hard-code-ish the aggregated files in the theme?

Thanks
Tom

Therefore, as you received Christ Jesus the Lord, so walk in Him, rooted and built up in Him and established in the faith, just as you were taught, abounding in thanksgiving. (Col 2:6-7)

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
No re-bootstrapping

You can do this without much code or any rebootstrapping of drupal. It's not all that hard actually :)

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com