I was reading through Which browsers support script async which is discussing Google's script which looks like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'xxx']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
In the SO post, it states:
The async support as specified by google is achieved using two parts:
using script on your page (the script is supplied by google) to write out a
<script>tag to the DOM.that script has
async="true"attribute to signal to compatible browsers that it can continue rendering the page.The first part works on browsers without support for
<script async..tags, allowing them to load async with a "hack" (although a pretty solid one), and also allows rendering the page without waiting for ga.js to be retrieved.The second part only affects compatible browsers that understand the
asynchtml attribute
This has me confused. What is the async attribute doing on the script above if they're already using another 'hack' to provide async support for browsers which do not respect the async: true attribute? Doesn't that hack work for all browsers?
typeeven recommended any more? I would say notlanguage.typehas also been deprecated since HTML5. See this SO question, which was answered 4 years ago: stackoverflow.com/questions/4195427/…