Tuesday, July 31, 2012

tags – how should my site handle ocassionally missing javascript files gracefully?



Say I\’ve got this script tag on my site (borrowed from SO).



<script type=\"text/javascript\" async=\"\"
src=\"http://edge.quantserve.com/quant.js\"></script>


If edge.quantserve.com goes down or stops responding without returning a 404, won\’t SO have to wait for the timeout before the rest of the page loads? I\’m thinking Chaos Monkey shows up and blasts a server that my site is depending on, a server that isn\’t part of a CDN and has a poor failover.


What\’s the industry standard way to handle this issue? I couldn\’t find a dupe on SO, maybe I\’m searching for the wrong terms.


Update: I should have looked a bit more closely at the SO code, there\’s this at the bottom:



<script type=\"text/javascript\">var _gaq=_gaq||[];_gaq.push([\'_setAccount\',\'UA-5620270-1\']);
_gaq.push([\'_setCustomVar\', 2, \'accountid\', \'14882\',2]);
_gaq.push([\'_trackPageview\']);
var _qevents = _qevents || [];
(function(){
var s=document.getElementsByTagName(\'script\')[0];
var ga=document.createElement(\'script\');
ga.type=\'text/javascript\';
ga.async=true;
ga.src=\'http://www.google-analytics.com/ga.js\';
s.parentNode.insertBefore(ga,s);
var sc=document.createElement(\'script\');
sc.type=\'text/javascript\';
sc.async=true;
sc.src=\'http://edge.quantserve.com/quant.js\';
s.parentNode.insertBefore(sc,s);
})();
</script>


OK, so if the quant.js file fails to load, it\’s creating a script tag with ga.async=true;. Maybe that\’s the trick.


Possible answer: http://stackoverflow.com/a/1834129/30946






Rating: 1 out of 5 based on 3 ratings



The post tags – how should my site handle ocassionally missing javascript files gracefully? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/tags-how-should-my-site-handle-ocassionally-missing-javascript-files-gracefully.html

No comments:

Post a Comment