MTK Android Based Phone IMEI Write Tool, DirecTV Now Launch Will Include Zero Rated Bandwidth on the Mobile Network, video entertainment product with a heavy mobile, Smartphone Apps Drive Content Usage, It will not surprise you that smartphones now are the ways most people interact with the Internet, Social Networking Web Server via Arbitrary Code Execution, Released Add New Method FOR Reset FRP Samsung

Saturday, September 10, 2016

All New Does 'script async' Really Make Javascript Asynchrounous?

All New Does 'script async' Really Make Javascript Asynchrounous? - do you know that every day there are new gadgets that are created with new advantages to simplify your life, on the blog Gadget Center we will discuss about the latest gadgets and gadgets that have long ranging from speck and price, now we will discuss about All New Does 'script async' Really Make Javascript Asynchrounous? we have collected a lot of news to make this article to be really useful for you, please see.

Articles : All New Does 'script async' Really Make Javascript Asynchrounous?
full Link : All New Does 'script async' Really Make Javascript Asynchrounous?

You can also see our article on:


All New Does 'script async' Really Make Javascript Asynchrounous?

You might be wondering, when Google's PageSpeed tells your website has "Render-Blocking Script". After a quick search on Google, finding similar topics on How to remove Render-Blocking Javascript, as stated by PageSpeed Insights. You would find that adding an "async" attribute to the "script" tag would do the job. But unfortunately, after all excitements, the "Don't be Evil" says the same thing again and again.



So, does adding an "async" attribute to the "script" tag really loads a javascript in an asynchronous way?

Well, as per w3cschools, "The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available.".

Is that correct? Did you check it by yourself? - Well, for me it didn't work out, as I expected.

Here below, I've found two wonderful code snippets that would really make a javascript run asynchronous.

The traditional Javascript way

function loadScript(src, callback)
{
var s,
r,
t;
r = false;
s = document.createElement('script');
s.type = 'text/javascript';
s.src = src;
s.onload = s.onreadystatechange = function() {
if ( !r && (!this.readyState || this.readyState == 'complete') )
{
r = true;
callback();//This function will be fired, after the javascript loaded from the remote URL.
    }
};
t = document.getElementsByTagName('script')[0];
t.parentNode.insertBefore(s, t);
}

The above function will create a "script" tag dynamically and then inserts it before the first "script" tag found in the DOM(Document Object Model).

The Jquery way

$.getScript(url, successCallback);//As simple as eating an Apple pie. ;)

The above code does the same job as the first one. But, the only downfall is, you need to load the Jquery library before doing this.

Thank me for getting your PageSpeed score to the peak. :)

And, let me know your queries through the comments section.



article titled All New Does 'script async' Really Make Javascript Asynchrounous? has been completed in the discussion

hopefully information about All New Does 'script async' Really Make Javascript Asynchrounous? can provide benefits for you in determining the gadget to suit your needs so much easier in living everyday life.

you just read the article entitled All New Does 'script async' Really Make Javascript Asynchrounous? if you feel this information is useful for you and want to bookmark it or want to share it please use link https://mjoaobrum.blogspot.com/2016/09/all-new-does-async-really-make.html.

Tag :
Share on Facebook
Share on Twitter
Share on Google+
Tags :

Related : All New Does 'script async' Really Make Javascript Asynchrounous?

0 comments:

Post a Comment