I've been experiencing an annoying bit of boost caching failure where the CSS and JS files are removed from /sites/default/files/[css|js] but the generated cached html refer to the files and generate 404. The cached CSS and JS files remain but are not served.
Now, I know that I shouldn't implement workarounds, rather I should probably have tried to solve this ahead of time, but workarounds were easier to implement :-) What I do is to copy the cached css and js files over to /sites/default/files/css|js and to make that process easier, I use various symlinks to ensure that all sites are sharing a common default/files/[css|js] but have distinct %HTTP_HOST/files
I had actually forgotten I'd done this until I had forgotten to create the symlinks on a newly boost-enabled site ... sure enough this morning the cached pages created overnight all had missing CSS and JS files (but again the cached versions were there). As you can probably guess, this makes a right mess of the pages served to anonymous visitors.
The workaround works but is both a pain in the butt and eventually going to cause a performance issue with all these saved (and mainly useless) CSS and JS files. Now, I'm not a mod_rewrite guru and so I assumed that the rewrite rules would only work if the original was available -- that is, /cached/%HTTP_HOST/sites/default/files/css/css_somefile.css_.css wouldn't get served unless /sites/%HTTP_HOST/files/css/css_somefile.css exists but I finally decided to spend some time pouring through all of the documentation boost comes with and my read of http://drupal.org/node/583264 (Serve cached pages from an Apache mirror using rsync) strongly suggests that the cached files should be served regardless of whether the originals exist.
So, now I'm wondering what exactly I've done wrong here ... the CSS and JS files are correctly created and cached for all sites but the originals are removed by boost cron runs and then the cached versions are not served, though I'm not sure why that is happening either given that the settings I use ... I would REALLY like to get this working without all this extra copying of files and use of symlinks ... it feels a bit like using duct tape in an auto-body shop.
I'm using the generated .htaccess rules with one change, I do cache SSL pages. Thoughts?
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | boost-632042.patch | 3.04 KB | mikeytown2 |
Comments
Comment #1
mikeytown2 commentedEven though the cached css files exist they are not being served; does this describe your issue in short? If the original css is gone, the cache still has it, thus via htaccess rules that css file will be available (this is how it should work).
Little bit of clarification, boost cron does not remove the original css files, drupal core does that.
How many sites do you have running off of this install? Does this error showup even with only 1 site for that install?
Comment #2
Dave Kinchlea commentedYou are much better at "succinct" than I! yes that is the problem entirely.
I run about a dozen sites and growing and yes, it shows up for all the sites, even the main site using "sites/default/settings.php". Pretty easy to test, I just delete something like /sites/default/files/css/css_83175784505a60a68cd2f3d58d82d04e.css and refresh an anonymous view requiring that file ... and then look at the ugly results of no CSS at all. Same for js.
Considering that this must be a mod_rewrite problem, I'll let you know that the web sites are behind NATed firewalls sharing IPs ... clearly HTTP_HOST is being set as that is how the sites are being accessed and the rules you provide seem pretty straight-forward ... they ought to be working. Just to be clear, the cached html files ARE being delivered as expected.
I'm stymied.
Comment #3
mikeytown2 commentedWould you mind posting you htaccess rules?
Comment #4
Dave Kinchlea commentedIt seems like this isn't too dangerous, but 20+ years worrying about computer security makes me nervous :-)...nonetheless, here you go
pretty darn close to out of the box I think...
Comment #5
mikeytown2 commentedyeah, nothing special in there... so html is working but css is not. What happens when you run with the full set of rules found in the htaccess2.txt file, does css caching work then?
Comment #6
Dave Kinchlea commentedWell, assuming you meant
boost/htaccess/boosted2.txt, the cached HTML is bypassed and dynamically created when I substitute those rules, which means it is pretty difficult to know whether the cached CSS and JS were used ... is there any apache debug setting you are aware of that would allow mod_rewrite to log what it is doing?Comment #7
mikeytown2 commentedLet me guess, your using pressflow?
In Anycase good question about rewrite logs
http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html#rewritelog
It only works in
Context: server config, virtual hostnot your htaccess file. So you can add this to the bottom of your httpd.conf fileThis outputs a crap load of information so only hit your css file, don't load the page containing the css reference. Look into the location of the log file; you might need to put it somewhere else.
Comment #8
Dave Kinchlea commentedNo, I'm responsible for my own mess I'm afraid :-) I'll look into it though, perhaps there is some lessons there for me.
Thanks for the rewrite pointer, I'll update when I learn more.
Dave
Comment #9
mikeytown2 commentedWhen going through the log the main thing to search for is
=> matched. Looking at=> not-matchedis also helpful if you know it should have been matched yet it wasn't. Also let me know if this is a bug with boost or something else; your last comment made it sound like it might be something else.Comment #10
Dave Kinchlea commentedHumour is just so hard to convey with the written word, I'm quite prepared to believe the error is mine not yours! In fact, I've assumed that all along. BUT "mess" is, I guess, the right word in this somewhat embarrassing case.
I do believe it is solved and turned out to be an errant virtual-host file in /etc/apache/sites-enabled which I removed just prior to putting in the rewritelog directive which promptly showed everything is working perfectly. The reasoning is a guess and the fault definitely mine, but the end result is fact.
I am going to get a lot less alerts now.
Your help has been invaluable! I'll be contributing to the mikeytown2 donation bin! Maybe I should go back and review apache docs, it has clearly been way too long!
Comment #11
mikeytown2 commentedWithout this, it probably would have taken a couple more days before I discovered this other bug; so not all is lost.
#632908: Pressflow + Gzip: CSS & JS files not being cached
Comment #12
Dave Kinchlea commentedI took the blame too quickly, it does turn out to be a Drupal thing....if my MAIN site has gzip-enabled CSS and JS per /admin/settings/performance then the cached css/js file is not delivered (I guess my extra virtualhost didn't have anything to do with it...I forgot I made this change, sigh. Sorry for the confusion, trying to work this in on the weekend.
So, the upshot is that the cached CSS and JS files will not be found if the CSS GZIP or Aggregator JS GZIP are enabled ... it looks like there are two engines trying to zip up the files and the rewrite rules can't really deal with the internal redirect to *.gz.
Makes total sense now that I see it written down like that :-)
Comment #13
mikeytown2 commentedBoost works with css gzip and the javascript aggregator gzip; since one is my project and the other is a patch that I wrote for the javascript aggregator. In any case, you can disable gzip on both projects and if you have gzip enabled at the top of the performance page and update your boost rules then you should get gzipped files. But it should work with the other modules enabled for CSS & JS.
Comment #14
Dave Kinchlea commentedi reopened this because I was thinking about it and it should be able to work together .. they way things are now I am losing GZIP on my CSS and JS files for authenticated users.
I can attach rewrite logs if you like.
Comment #15
mikeytown2 commentedSo you have gzip enabled for the css & js modules but gzip disabled on the page cache section correct?
Comment #16
Dave Kinchlea commentedThat is correct (though actually, I've chosen to disable GZIP/JS compression preferring the cache instead)
Comment #17
mikeytown2 commentedIf you want it to work with your selection of settings this is how the rewrite rules would have to be
Comment #18
Dave Kinchlea commentedThose look like the same rules I sent you, just rearranged in a different order, is that what you expected?... perhaps my old eyes are missing some change, but regardless it had no effect .... I'll test some more, perhaps my convoluted symlink nightmare (which frankly isn't as bad as all that) caused something to fail but I think not.
Comment #19
mikeytown2 commentedThe rearranged rules make it so you wont get the cached css/js files unless your logged out; key part is the skip
RewriteRule .* - [S=2]toRewriteRule .* - [S=4]Comment #20
Dave Kinchlea commentedWell, with them in place (copy-and-paste from your note), existing unauthenticated users do not get the cached page if the main site (and only the main site) has GZIP enabled....all of the other sites can have gzip enabled but if/when the main site (from default/settings.php) has gzip enabled then the rewrite fails ... the order of the rules does not make any difference. (or the rewrite difference I missed, obviously).
Comment #21
Dave Kinchlea commentedWell, with them in place (copy-and-paste from your note), existing unauthenticated users do not get the cached page if the main site (and only the main site) has GZIP enabled....all of the other sites can have gzip enabled but if/when the main site (from default/settings.php) has gzip enabled then the rewrite fails ... the order of the rules does not make any difference.
Comment #22
mikeytown2 commentedWhat does the rewrite.log file show in your test?
Comment #23
Dave Kinchlea commentedAfter much trial and error I've found the issue ... I think anyway. Parsing those logs is a bit of a pain, I found it somewhat easier to do more directed trial and error. What I've found is that with GZIP enabled for the site then the rewrite request becomes:
sites/default/files/css/css_0056d2dbf1eb4865b7831f5ff92a8817.css.gzwhich does not match what is in the boost GZIP cache of:
cache/gz/www.livelink-experts.com/sites/default/files/css/css_0056d2dbf1eb4865b7831f5ff92a8817.css_.css.gzSo, when drupal clears the css cache, the gzipped version goes away and the cached version isn't found. Now that I understand what is going on I can work on rewrite rules that will do what I need; and failing that I have a much better workaround in mind :-)
Comment #24
mikeytown2 commentedWhat your describing makes sense, but shouldn't be happening. The rewrite rules for the webroot get called first, so it should go to the cached version first. In any case try these rules
Comment #25
mikeytown2 commentedalso here is a patch that will also create the .css.gz_.css.gz files. Let me know if either one works by its self or if both are needed (rules above and this patch).
Comment #26
Dave Kinchlea commentedHi Mike
Just wanted to give you an update because you seem to take such an interest in support ... I had very little time yesterday to play around, I did quickly try both the patch and the new rules, neither made a difference alone or together -- I still seem unable to serve the _css.gz files. I've no time for the next couple days to look at this, but I will get back to it because I definitely want GZIP to work for both CSS and JS ... those files are huge on my site!
Comment #27
Dave Kinchlea commentedHi Mike
I finally found the time to do some more digging and you have good news coming I think. What I have verified is that the mod_rewrite is working, boost is working, in fact all is working EXCEPT that my primary server provides the gzipped CSS file to the client in a way that the client doesn't understand it to be gzipped.
Now, the rule in the .htaccess, as you know, is supposed to match %{HTTP:Accept-encoding} !gzip which means that the client accepts gzip encoding, it then looks for a matching file and serves it up... all verified via mod_rewrite logging and a 200 status in access.log but the following URL doesn't work http://www.kinchlea.net/sites/default/files/css/css_75af379721f9360ff83d... ... I am presented with the Drupal "page not found" but using a different server using the same code (NFS mounted) I get the expected CSS content.
The only significant difference I can think of between the two servers is one is the 64-bit version of Ubuntu 9.04 while the other is the 32-bit version... both the same versions (but different compiles) of apache, both same modules installed, same config files. Clearly there is some difference but I'll be damned if I know what it is. I think I may just have to rebuild this server and see if that clears my problems (but then of course I'll never know what the problem was).
In any case, as I said, it can't be boost nor does it appear to be boost's .htaccess rules, so this is now closed.
Comment #28
mikeytown2 commentedWhats the difference between the headers of the 2 different servers for the same file?
Comment #29
Dave Kinchlea commentedWell, in the end I'm not sure whether to be proud and happy or embarrassed and happy, but I'm happy just the same!
The problem was the .htaccess created by css gzip in ./sites/default/files/[css|js], when it exists it produces seemingly unpredictable behaviour; most often (I even might go so far as to say always but I thought I had seen different behaviour earlier... I've tried so many incarnations that I am probably mixing them together) the behaviour is that mod_rewrite stops processing the current URI after processing that file regardless of the outcome...essentially making ./sites/default/files/[css|js] the only available caches for CSS and JS files.
Checking off the appropriate no .htaccess radio button in admin/settings/performance and following the directions by moving the rewrite rules into ./.htaccess and poof all is working perfectly. If I had to guess, which I don't but I like to just the same, I'd say it was the recursive use of
<ifmodule mod_rewrite.c>blocks but I didn't even try to determine the full story, just happy enough to finally put an end to this niggling problem once and for all.The reason it looked like different behaviour for different servers was simply because I managed to confuse myself as to which server I was connecting to, while it was up to date and synced vis-a-vis file system, configuration and DB, it wasn't clearing any caches (or indeed running cron at all) so the gzipped files in sites/default/files/ were there to be found by both apache and me (through find(1)).
ANYWAY, while I know my site is uncommon, I am not convinced that this problem is unique to me ... perhaps I'm the only one who hadn't automatically combined the .htaccess files? Doing so was on my future performance tuning todo list but I hadn't really assumed there was any problem to worry about. Silly rabbit, trix are for kids :-)
Comment #30
mikeytown2 commentedGood to know... I'll have to play around with the htaccess rules for that module, to see what the issue is.
Comment #31
Anonymous (not verified) commentedIs this issue really solved? Often when I visit my boosted pages in IE, I get a "jQuery not defined" message. The jquery.js is apparently not loaded. This happened today with the latest boost 6.x-1.17. When I "Clear all boost cached data" - site loads fine again.
I also was using css gzip, javascript aggregator and boost cache for css / js.
I think the following happens:
- uncached page is visited >> gets boosted OK
- cached page is OK, jquery is OK
- after a while "something happens"
- suddenly jquery "not defined", page crashes IE
Can it be CRON does something, like delete a file flagged "temporary", which is actually being used for boost?
Im gonna try different settings, and report back what the solution was.
Comment #32
Anonymous (not verified) commentedDamnit, solved already, it was this:
IE cant handle 30+ CSS files or so (it crashes JS then). So when I turned off CSS aggregation for some testing, boost cached a page with 30+ CSS files. That explained the bosted crashing in IE.
Comment #33
haggins commentedI've got the same problem. Log tells me:
page not found: sites/default/files/ctools/css/65d11fe0207832efef54e9a05888a9e0.css?h
even the file exists. gzip compression is deactivated at core and boost - tab. But I can not turn of css aggregation since IE cannot handle that much files.
Comment #34
haggins commentedI had to disable boost now since anonymous users didn't get any css or js - files. I tried difference settings witz gzip-compression enabled/disabled, cache css/js and don't cache but everything resulted in unformatted html.
Could you point me in any direction please?
Comment #35
haggins commentedSince I enabled gzip every visitor gets all necessary js and css. But there's a css generated by panels which is not needed but everytime included. So the following issue is not critical for me but it is flooding my log:
After 1st cron sites/default/files/ctools/css/65d11fe0207832efef54e9a05888a9e0.css is missing
.
.
a lot of "page not found" entries in log
.
.
After 2nd cron everything is fine and sites/default/files/ctools/css/65d11fe0207832efef54e9a05888a9e0.css exists
.
.
After 3rd cron sites/default/files/ctools/css/65d11fe0207832efef54e9a05888a9e0.css is missing again
.
.
a lot of "page not found" entries in log
.
.
After 4th cron everything is ok
.
.
and so on...
It seems as every cron would create/delete this file by turn. And all boost-cached files are referencing to it whether the file exists or not.
Comment #36
mikeytown2 commented@haggins
you have the css cache enabled for boost?
Comment #37
haggins commentedyes, boost .css and .js caching is enabled. Version 6.x-1.x-dev.
css/js aggregation is enabled, too.
Comment #38
frankcarey commentedmikeytown2 - can you clarify this point? Can you just enable the settings for caching js and css on the performance page or does that not really have any effect until you have to added/changed the .htaccess file ?
The UI makes it seem like you just need to set it there, but I'm thinking that on and off don't matter... only the rules in .htaccess matter.
Thanks!
Comment #39
mikeytown2 commentedboth matter; htaccess & the settings. Otherwise the css files won't be in the boost cache OR the files in the cache won't get served.
Comment #40
denniemans commentedSame problem here! Hope there's a solution