Headway body classes and W3TC page cache conflict

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.

Read More

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

The code looks like this

<!-- mfunc -->
headway_page_top();
<!-- /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.

Related posts

Leave a Reply

1 comment

  1. 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?