Closed (fixed)
Project:
Basic
Version:
6.x-2.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
25 Mar 2009 at 16:09 UTC
Updated:
22 Apr 2013 at 20:07 UTC
Jump to comment: Most recent
I discovered today that if you enable caching (under Config -> Performance), then "browser-xxx" body classes are no longer rendered on a browser by browser basis. Instead, the first browser to load a page after the cache is cleared will set it, and all other page loads will get that same class, no matter what browser they are running. For example, if I clear the cache, and then load a page in IE7, and then load the same page in FF3, it still says browser-ie instead of firefox3. Any workaround besides just not using Drupal's cache (which is obviously not good)?
Comments
Comment #1
mcrittenden commentedJust tried adding drupal_rebuild_theme_registry() to the top of page.tpl.php and that didn't seem to make a difference.
Comment #2
mcrittenden commentedComment #3
Anonymous (not verified) commentedThis is bad..
I'll remove the code and see if there's a way to fix that.
Thanks.
Comment #4
SteveK commentedClearing the variables cache will fix this problem for the time being. I'm trying to figure out a better way of doing this though without having to clear the var cache each time.
You'll have to rebuild the theme and you can either place this in your template file, in a hook_init() function, or at the top of your page.tpl.php.
Potential solutions would be:
Let me know if this works for you. :)
Comment #5
SteveK commentedsorry, the correct code would be:
note that this will defeat the whole purpose of having page caching enabled to begin with so you're better off turning page caching off.
Comment #6
mcrittenden commentedSo no fixes? I've been hunting around for a way to selectively remove a certain bit of code from the cache but no luck.
Comment #7
Anonymous (not verified) commentedNo luck so far, Steve spend a fair amount of time hunting the same thing with no real result. Still hoping :)
Comment #8
mcrittenden commentedThanks for trying! I'd chalk this up as a limitation with Drupal...maybe an issue should be posted to core so that a workaround is implemented in D7?
Comment #9
SteveK commentedPossibly... the main reason for page caching though is to reduce the amount of queries sent to the database. What happens is that the user who initiates the first call has all the classes and html markup saved in a serialized in the database. The next time an anonymous user hits the same page, the user will be presented with that same markup. The work around for this would be to disable page caching or drop the page cache, load up a new page for the user, then set the cache again (which is a tad redundant). Another work around would be to save 6 or 7 version of the cache then serve the correct one depending on the browser type. In my opinion, this would be overkill for just 1 class.
I suggest turning off page caching in the meantime until a stable work around is found.
Comment #10
mcrittenden commentedWorks for me. Thanks. Can still enable block caching, compression, and CSS & JS optimization anyway, which helps a lot.
Comment #11
SteveK commentedI found a JS script that would work for applying a browser class to the body. It depends on JS being enabled but will allow you to turn on page caching if needed.
http://rafael.adm.br/css_browser_selector
Comment #12
SteveK commentedthis has been depreciated in newer versions.
Comment #13
mcrittenden commentedComment #15
ericbroder commentedI had a similar problem with Drupal page caching making it difficult to add a browser-related body class. I'm using a Zen Sub-theme (not Basic). I decided to use javascript/jquery so that the browser detection is performed outside of the page caching system.
For example:
See also: How to detect screen size and apply a CSS style.
Comment #16
hockey2112 commentedI know this thread is old, but I just wanted to say that #15 fixed my issue very nicely. Thanks!