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';
开发者_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;
精彩评论