Skip to content

Instantly share code, notes, and snippets.

@danott
Created November 28, 2011 22:04
Show Gist options
  • Save danott/1402295 to your computer and use it in GitHub Desktop.
Save danott/1402295 to your computer and use it in GitHub Desktop.
Replace Twitter/Facebook/G+ scripts with one Modernizr.load call.
Modernizr.load(
[ '//platform.twitter.com/widgets.js'
, '//apis.google.com/js/plusone.js'
, { test: document.getElementById('facebook-jssdk')
, nope: '//connect.facebook.net/en_US/all.js#xfbml=1'
}
]);
/* When Using Modernizr, the above replaces all the social includes below
<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
<!-- Google+'s inline script -->
<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>
<!-- Facebook's inline script -->
<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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
*/
@xblondel
Copy link

Hello,
I'd like to use Modernizr.load call
I have also seen this on github :https://gist.github.com/1025811
I want to call google plus , facebook and google analytics.
But i want to be able to attribute them the correct id : facebook-jssdk for facebook, ga for analytics , and so on
Any idea how to do it with Modernizr.load call ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment