Google Page Speed Insights
"Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML."
The above issue is prompting me for my 2 stylesheets. So I load my stylesheets with the below code to defer the loading of the stylesheets.
window.onload = loadResource;
function loadResource(){
css_array=[resource1,resource2];
css_init(css_array);
}
function css_init(hrefPath){
for(a = 0; a < hrefPath.length; a++){
link=document.createElement('link');
link.href=hrefPath[a];
link.rel='stylesheet';
document.getElementsByTagName('head')[0].appendChild(link);
}
}
with the above code all the css stylesheets are loaded after the DOMContentLoaded Event
and Load Event
has been fired (Network tab of chrome dev tools)
But even with the above the render blocking issue is still unfixed. Any idea why it didn't work and how to properly defer css stylesheets? thanks for the help!
How do I eliminate render-blocking resources in WordPress? Try deferring JavaScript, generating critical CSS, and inlining it (usually done through a cache plugin or Autoptimize). Trimming the size of CSS and JavaScript files and delaying third-party code can also eliminate render-blocking resources in WordPress.
This is a slightly complex issue. Take a look at these (read the comments, too):
Also, you could give head.js
a try: http://headjs.com/
Do you have a good reason to load the CSS like this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With