Reputation: 139
i'm trying to improve speed of my website. i'm using PageSpeed Insights to check my site performance and it was telling me to remove render blocking java script and css. so i did it and know its causing problem in my website design. so what should i do to remove rendering blocking without causing problem in my website design.
Upvotes: 1
Views: 627
Reputation: 24825
Render blocking CSS will always show on Google Page Speed Insights if you are using external resources for your CSS.
What you need to do is to inline all of your 'above the fold' styles in <style></style>
tags in the head of your web page.
I will warn you, this is NOT easy and plugins that claim to do this often do not work, it requires effort.
To explain what is happening:-
Point 4. is the render blocking
as those resources are stopping the page from rendering the initial view.
To achieve this you need to work out every element that displays without scrolling the page and then find all the styles associated with those elements and inline them.
This one is simpler to fix.
If you are able to use the async
attribute on your external JS then use that.
However be warned that in a lot of cases this will break your site if you have not designed for it in the first place.
This is because async
will download and execute your JS files as fast as possible. If a script requires another script to function (i.e. you are using jQuery) then if it loads before the other script it will throw an error. (i.e. your main.js
file uses jQuery but downloads before it. You call $('#element')
and you get a $ is undefined
error as jQuery is not downloaded yet.)
The better tag to use if you do not have the knowledge required to implement async
without error is to use the defer
attribute instead.
This will not start downloading the script until the HTML has finished parsing. However it will still download and execute scripts in the order specified in the HTML.
Upvotes: 1
Reputation: 1635
Add async in the script tag and put the css and js in the last of the page
Upvotes: 0