This is the code google recommends you use to call in the ga.js file:
(function() {
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);
})();
as the file is inserted into the dom does this prevent the js file from being cached by the browser?
No. Caching is based on response headers for the ga.js file. It is dynamically inserted so that its loaded asynchronously, meaning the load doesn't block the browser from doing other activities (rendering, painting etc). A few browsers understand the async attribute in the script tag. Note the
ga.async = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With