Previously, we talked about how to deliver Javascript in blocking way and Defer Parsing of Javascript in WordPress. CSS part on that guide was probably not optimal. Here is How to Load CSS Without Blocking Rendering in WordPress & Others. Render Blocking CSS is Common Error on Google PageSpeed Insights. In this guide, we will remove the rest of the blocking CSS.
How to Load CSS Without Blocking Rendering WordPress : Where To Start From?
Problems are more in WordPress as control of delivery CSS, Js is lesser. For the sake of GooglePage Speed, this is very good plugin :
1 | https://wordpress.org/plugins/async-js-and-css/ |
There are more such plugins for WordPress. On that plugin, we use this setting :
---
Load Javascript asynchronously [ticked]
Detect tags in wp_head [not ticked]
Load CSS asynchronously [ticked]
CSS loading method [(default)Inserting all CSS styles inline into the document HEADER]
Minify CSS [ticked]
Remove “?ver=XXX” part from URLs [ticked]
Exceptions (files to ignore and load in render-blocking way) [none]
That settings inline some CSS leaving Font CSS, Icon Font CSS and other few CSS to inline. They show as Load CSS Without Blocking Rendering message on Google PageSpeed Insights. This may be your case or slightly different. We already made critical CSS inline.
How to Load CSS Without Blocking Rendering WordPress & All Others
Normally we load CSS in this way :
1 | <link rel="stylesheet" href="https://cdn.thecustomizewindows.com/css1.css" media="all"> |
But if we load the same in this way :
1 | <link rel="stylesheet" href="https://cdn.thecustomizewindows.com/css1.css" media="none" onload="if(media!='all')media='all'"> |
The CSS not going to block the rendering. But the technique uses JavaScript. For the browsers with no-JavaScript enabled, we need to offer a second way (which is blocking way) :
1 2 | <link rel="stylesheet" href="https://cdn.thecustomizewindows.com/css1.css" media="none" onload="if(media!='all')media='all'"> <noscript><link rel="stylesheet" href="https://cdn.thecustomizewindows.com/css1.css"></noscript> |
But if you add both set to header, again on Google PageSpeed Insights on mobile you’ll get info that CSS is blocking rendering. So final fix is, put this part on header :
1 | <link rel="stylesheet" href="https://cdn.thecustomizewindows.com/css1.css" media="none" onload="if(media!='all')media='all'"> |
and the noscript
part on footer :
1 | <noscript><link rel="stylesheet" href="https://cdn.thecustomizewindows.com/css1.css"></noscript> |
I have not seen problem on MacOS Safari, Chrome, Firefox with this method for non-critical CSS. MacOS Opera probably can not load properly. We hope, you’ll get some score like this :
For making failsafe, I have to send you here :
1 | https://github.com/filamentgroup/loadCSS |
Tagged With Eliminate render-blocking resources css/stylesheet without plugins , https://thecustomizewindows com/2016/10/load-css-without-blocking-rendering-wordpress-others/ , wordpress css loading slow