Info Tentang Does 'script async' Really Make Javascript Asynchrounous? Update Terbaru 2017 Gratis

Sedikit Info Seputar Does 'script async' Really Make Javascript Asynchrounous? Terbaru 2017 - Hay gaes kali ini team Apps Android Games, kali ini akan membahas artikel dengan judul Does 'script async' Really Make Javascript Asynchrounous?, kami selaku Team Apps Android Games telah mempersiapkan artikel ini untuk sobat sobat yang menyukai Apps Android Games. semoga isi postingan tentang yang saya posting kali ini dapat dipahami dengan mudah serta memberi manfa'at bagi kalian semua, walaupun tidak sempurna setidaknya artikel kami memberi sedikit informasi kepada kalian semua. ok langsung simak aja sob
Judul: Berbagi Info Seputar Does 'script async' Really Make Javascript Asynchrounous? Full Update Terbaru
link: Does 'script async' Really Make Javascript Asynchrounous?
"jangan lupa baca juga artikel dari kami yang lain dibawah"

Artikel Terbaru Does 'script async' Really Make Javascript Asynchrounous? Update Terlengkap 2017

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.

Itulah sedikit Artikel Does 'script async' Really Make Javascript Asynchrounous? terbaru dari kami

Semoga artikel Does 'script async' Really Make Javascript Asynchrounous? yang saya posting kali ini, bisa memberi informasi untuk anda semua yang menyukai Apps Android Games. jangan lupa baca juga artikel-artikel lain dari kami.
Terima kasih Anda baru saja membaca Artikel Tentang Does 'script async' Really Make Javascript Asynchrounous?