var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
ga.async = true;
ga.js
script will not block the execution of other asynchronous scripts.insertBefore
instruction. It turns out that some browsers block the execution of scripts if the script with the insertBefore
instruction has not yet been loaded. Naturally, this slows down the loading of the page. In other words, such browsers will wait until the Google Analytics module is loaded on the page, and until this point all other scripts are blocked. The parameter ga.async = true corrects the situation in many modern browsers. But not all.insertBefore
. He collected statistics from 60+ different browsers - as seen in the table by reference, the main “offender” is the Opera browser. You can run the test and check here .Source: https://habr.com/ru/post/136360/
All Articles