Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render blocking defer vs moving script at bottom

Tags:

People also ask

Should I use defer in script tag?

You should use defer for all other scripts. defer is great because it: Gets loaded as soon as possible — so it reduces load times. Doesn't execute until everything you need is ready — so all the DOM you need is there.

Is script render blocking?

Simply put, JavaScript is a piece of code that might be present on your website to enable some functions of your theme or plugins. And “Render Blocking” means that these JavaScript codes are either blocking, or slowing down how your website is displayed, or rendered, by your browser.

What is the purpose of defer script tag?

Scripts with the defer attribute will execute in the order in which they appear in the document. This attribute allows the elimination of parser-blocking JavaScript where the browser would have to load and evaluate scripts before continuing to parse.

What is the difference between script script async and script defer?

Async - means execute code when it is downloaded and do not block DOM construction during downloading process. Defer - means execute code after it's downloaded and browser finished DOM construction and rendering process.


I assume moving script at bottom is same as using defer or async attribute. Since defer and async are not fully legacy browser compliant, I gone with loading script at the bottom of the page.

<html> <body> <!-- whole block of html --> <script type='text/javascript' src='app.js'></script> </body> </html> 

Before doing this, I ran performance benchmark tools like GTmetrix and Google PageSpeed insight. Both shown 'render blocking' parameter as the main problem. I am bit confused now, as even after I moving these scripts at the bottom to allow content/html to load first; these tools still report render blocking as a main problem.

I did look at the other StackOverflow posts highlighting that though scripts loaded at the bottom has to have 'defer' attribute.

I have several questions:

  1. is above true?
  2. are these tools specifically look for 'defer' or 'async' attribute?
  3. if I have to give a fallback w.r.t defer ( specifically for IE browsers), Do I need to use conditional statements to load non-defered scripts for IE?

Kindly suggest the best approach. Thank you in advance.