Created
November 26, 2012 17:18
-
-
Save girlcheese/4149467 to your computer and use it in GitHub Desktop.
Asynchronous code injection
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
<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> |
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
<script> | |
var resource = document.createElement('script'); | |
resource.src = "//third-party.com/resource.js"; | |
var script = document.getElementsByTagName('script')[0]; | |
script.parentNode.insertBefore(resource, script); | |
</script> |
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
(function(d, t) { | |
var g = d.createElement(t), | |
s = d.getElementsByTagName(t)[0]; | |
g.src = '//third-party.com/resource.js'; | |
s.parentNode.insertBefore(g, s); | |
}(document, 'script')); |
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
<!-- N.B. Not async! --> | |
<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> |
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
<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> |
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
<script async src="http://third-party.com/resource.js"></script> |
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
<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> |
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
<script type="text/javascript"> | |
TypekitConfig = { | |
kitId: 'abc1def' | |
}; | |
(function() { | |
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; | |
try { Typekit.load(TypekitConfig); } catch (e) {} | |
}; | |
var s = document.getElementsByTagName('script')[0]; | |
s.parentNode.insertBefore(tk, s); | |
})(); | |
</script> |
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
$.ajax({ | |
url: '//third-party.com/resource.js', | |
dataType: 'script', | |
cache: true, // otherwise will get fresh copy every page load | |
success: function() { | |
// script loaded, do stuff! | |
} | |
} |
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
yepnope.injectJs("//third-party.com/resource.js", function () { | |
// script loaded, do stuff! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment