If you care about web performance of your WordPress site and are chasing top page speed scores as measured by tools such as Google Insights, there’s a good chance that you’re using W3 Total Cache plugin to minify and combine JavaScript and CSS files.
Page Speed measurement tools will usually recommend that you remove render-blocking JavaScript and CSS out of the <head>
tag, since every external file in the <head>
has to be download by the browser before the page is rendered. By moving CSS and JS out of the header and into the footer, then we avoid render blocking and can significantly increase our page speed scores.
Moving the minified JavaScript created by W3 cache plugin is relatively easy. We have a number of ways to do this in WordPress:
<!-- W3TC-include-js-head -->
before the closing </body>
tag.CSS is considered more important to place in the header as we don’t want our visitors to see un-styled content display briefly before the CSS has loaded.
Web performance advocates however will recommend moving the main CSS file(s) to the footer before the closing </body>
tag and in-lining critical display styles within the <head>
.
With W3 Total cache, we can move all combined and minfiied styles to the footer by using the following:
<!-- W3TC-include-css -->
Just drop this line before wp_footer(), as we still want the CSS to be loaded prior to our JavaScript files.
Not working for me? mine looks like this:
but doesn’t work, I have minified enabled on JS and CSS manually, but still get error saying Your page has 3 blocking CSS resources. This causes a delay in rendering your page?
so I put it in the footer.php in my child theme right above wp_footer(), as you said and it works, page speed insights no longer saying the file is blocking anything but now some css elements seam not to be loading all as my pages look different, I guess that’s where putting important css in the head comes in.
actually when I take all but one style sheet out of w3 my site still is not styled right but if I take all out of w3 then its styled right again but of course that defeats the purpose. so it seams putting the w3 combined file in my footer for some reason making my site style not look correct
ok, so it does work, however it makes some css, in my case a good bit not listen, But I was able to fix it by putting the !important tag behind the css that wasn’t listening. I didn’t finish but it worked on all the ones I done.
Hi Martin, yes footer.php in vast majority of themes should be the correct file.
hi, this tricks work on moving the css successfully. and the web site work fine. but when i check it at validator.w3.org, it show “Element link is missing required attribute property” from css that just moved. i should add property=’stylesheet’ to have it fixed. any idea how to add this on minified css? thanks
found the solution, have to adding it on minify.php manually on w3-total-cache/lib/W3/Plugin/
Well, i followed your advise and placed both lines in footer and i saw a very nice improvement on loading time.
Took me 2+ months to find the right solution.
Thank you very much!
Do you have a knowelenge on how to set w3-total-cache?
If you can point me to a reliable tutorial, cos so far i only found pieces, but not a complete and in detail. Specialy for minify set up.
Thanks again.
Hi, I’ve used the codes for the JS/CSS files, and some have moved to the footer, but some have not, and the PageSpeed Insights still kicks out the errors.
Advice?
Hi, thanks for this info which I’ve implemented & seems to have placed the CSS & JS files at the footer accordingly.
However, when I check the page speed performance with Google’s PageSpeed Insights it still gives me the “Eliminate render-blocking JavaScript and CSS in above-the-fold content”.
I expected to see a vast improvement & can’t understand why it hasn’t – is it something to do with clearing caches perhaps?
I need more detailed explanations on how to do this? I am using Genesis with a child theme and am not sure where/how to do this. The js and css files that are causing my warnings: Remove render-blocking JavaScript:
are actually the w3 minify js and css and the google fonts
Thank you for your help!
Hi i have kind of the same problem as Tami.
I added the following lines to my functions.php which loads “” right before the footer. And “” to load right after the footer. When inspecting the the page source i see them being printed, although pagespeed insights still states that they are render-blocking JavaScript and CSS in above-the-fold content (for the W3 css and js file).
Thanks!
my code in functions.php:
add_action (‘genesis_before_footer’,’bsg_load_css_to_footer’, 4 );
function bsg_load_css_to_footer() {
echo ““;
}
add_action (‘genesis_after’,’bsg_load_js_to_footer’, 5 );
function bsg_load_js_to_footer() {
echo ““;
}
Working in my case but some parts of the theme is broken. Probably some required js is causing this issue.
Howdy ! The details provided by Tom Elliott climbed a high note in google speed! Thanks Tom!
Snippet doesn’t work. It seems W3TC moved “move render blocking CSS to footer” inside premium version.
Thanks! That helps!