I'm currently working on a website using WordPress, Headway, Modernizr and W3 Total Cache. The problem I'm having is that W3TC is caching the body tag, which means that this isn't being updated depending on the users browser by Modernizr.

An example of how this is a problem is that modernizr adds the 'firefox' body class, if this is then cached then in chrome, we have that same 'firefox' body class which makes any browser specific css inaccurate.

I have tried using <!-- mfunc -->any PHP code<!-- /mfunc --> that I got from this answer

The code looks like this

<!-- mfunc -->
<!-- /mfunc -->

I have experimented with using the same mfunc wrapper inside the headway_page_top() function so that it is directly around the body tag without success. The error I get comes from W3TC and says 'Unable to execute code:' and then all the markup wrapped by the mfunc is printed out (in debug mode). This also happens with debug mode disabled.

This call is happening inside wp-content/themes/headway-2012/header.php, and I have added that path to the 'Cache exception list' inside the W3TC Page Cache settings to no avail.

Does anyone have any suggestions as to how I can have the page cache run side by side with modernizr and not have this problem?

EDIT: This problem isn't to do with Modernizr at all, I jumped the gun in thinking that it was. Headway is adding the body class in on its own and isn't using modernizr to do so. The problem is using W3TC and its fragment so that the body class remains dynamic. I haven't managed to get the fragment caching working at all, or find much documentation on it.

Is fragment caching a feasible solution? I seem to be running out of possible solutions.

closed as off-topic by gmazzap, Mark Kaplun, Nicolai, birgire, Pieter Goosen Aug 25 '14 at 4:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – gmazzap, Mark Kaplun, Nicolai, birgire, Pieter Goosen
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I might have been a bit confused earlier. Headway is putting the body class together. I'm going to switch it to modernizr to see if that fixes the problem. – supajb Jan 9 '12 at 0:51
  • Close-voted as too localized. As Headway is a commercial Theme, you should consult the support offerings of the developer, Headway Themes. – Chip Bennett May 7 '12 at 19:03

Caching shouldn't affect Modernizr since it's a client-side script and will run every time the page is visited.

I haven't used Headway but from what you describe it sounds like a server-side script in Headway is sniffing the browser and that's the result being cached.

Does that make sense?

  • You're right, it isn't modernizr being cached but a headway call. I was a bit rushed when I wrote the initial question and my edits weren't very clear. The fragment caching on the W3TC plugin however isn't working for me around that call. – supajb Jan 12 '12 at 3:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.