Created
January 6, 2012 21:55
-
-
Save chriscoyier/1572573 to your computer and use it in GitHub Desktop.
How some different companies load their third-party JS async style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Google Analytics --> | |
<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-XXXXX-X']); | |
_gaq.push(['_trackPageview']); | |
(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); | |
})(); | |
</script> | |
<!-- Optimized version: http://mathiasbynens.be/notes/async-analytics-snippet --> | |
<script> | |
var _gaq = [['_setAccount', 'UA-XXXXX-X'], ['_trackPageview']]; | |
(function(d, t) { | |
var g = d.createElement(t), | |
s = d.getElementsByTagName(t)[0]; | |
g.src = '//www.google-analytics.com/ga.js'; | |
s.parentNode.insertBefore(g, s); | |
}(document, 'script')); | |
</script> | |
<!-- BuySellAds --> | |
<script type="text/javascript"> | |
(function(){ | |
var bsa = document.createElement('script'); | |
bsa.type = 'text/javascript'; | |
bsa.async = true; | |
bsa.src = '//s3.buysellads.com/ac/bsa.js'; | |
(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa); | |
})(); | |
</script> | |
<!-- Typekit --> | |
<script type="text/javascript"> | |
TypekitConfig = { | |
kitId: 'abc1def', | |
scriptTimeout: 3000 | |
}; | |
(function() { | |
var h = document.getElementsByTagName('html')[0]; | |
h.className += ' wf-loading'; | |
var t = setTimeout(function() { | |
h.className = h.className.replace(/(\s|^)wf-loading(\s|$)/g, ''); | |
h.className += ' wf-inactive'; | |
}, TypekitConfig.scriptTimeout); | |
var tk = document.createElement('script'); | |
tk.src = '//use.typekit.com/' + TypekitConfig.kitId + '.js'; | |
tk.type = 'text/javascript'; | |
tk.async = 'true'; | |
tk.onload = tk.onreadystatechange = function() { | |
var rs = this.readyState; | |
if (rs && rs != 'complete' && rs != 'loaded') return; | |
clearTimeout(t); | |
try { Typekit.load(TypekitConfig); } catch (e) {} | |
}; | |
var s = document.getElementsByTagName('script')[0]; | |
s.parentNode.insertBefore(tk, s); | |
})(); | |
</script> | |
<!-- The Deck... is this async? Just document.writing ? --> | |
<script type="text/javascript"> | |
//<![CDATA[ | |
(function(id) { | |
document.write('<script type="text/javascript" src="' + | |
'http://connect.decknetwork.net/deck' + id + '_js.php?' + | |
(new Date().getTime()) + '"></' + 'script>'); | |
})("DF"); | |
//]]> | |
</script> | |
<!-- Facebook --> | |
<div id="fb-root"></div> | |
<script>(function(d, s, id) { | |
var js, fjs = d.getElementsByTagName(s)[0]; | |
if (d.getElementById(id)) return; | |
js = d.createElement(s); js.id = id; | |
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=200103733347528"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'facebook-jssdk'));</script> | |
<!-- Twitter --> | |
<a href="https://twitter.com/share" class="twitter-share-button">Tweet</a> | |
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> | |
<!-- Google Plus --> | |
<!-- Place this tag where you want the +1 button to render --> | |
<g:plusone annotation="inline"></g:plusone> | |
<!-- Place this render call where appropriate --> | |
<script type="text/javascript"> | |
(function() { | |
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; | |
po.src = 'https://apis.google.com/js/plusone.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you seen this: https://gist.github.com/1025811