Obsession with non-blocking scripts

Since I discovered the concept of non-blocking scripts , I became obsessed with loading all of my external scripts this way. I even hacked Joomla! templates (which I know are bad practice) to load non-blocking scripts into the index.php file. Sample code below.

(function() { var script = document.createElement('script'), head = document.getElementsByTagName('head')[0]; script.type = 'text/javascript'; script.src = "http://www.mywebsite.com/scripts/one_of_many.js" head.appendChild(script); })(); 

My questions:

When is it useful / bad to load non-blocking scripts?

What should be the limit for using non-blocking scripts?

+6
optimization javascript
source share
2 answers

The technique used for non-blocking scripts (adding a DOM script element) will not support the script execution order in all browsers, only in Firefox and Opera.

If you do not need the order of execution, you can use it safely.

If not, you can combine it with other methods such as defer script for IE, script in iframe or XHR.

Read more on Even Faster Websites

+1
source share

If you download a lot of files, even if they are non-blocking, which you can achieve by simply putting them at the end, you will have the html in front of the </body> , since browsers do something on the page if you download a lot.

It’s good to do this, but it’s better to see how file merging and minimization / insult is to shave off even more time. Another obvious thing is to make sure you are GZipping JS, which is sent to the browser.

0
source share

All Articles