Skip to content

Instantly share code, notes, and snippets.

@zenorocha
Last active November 14, 2022 12:18
Show Gist options
  • Save zenorocha/5161860 to your computer and use it in GitHub Desktop.
Save zenorocha/5161860 to your computer and use it in GitHub Desktop.
Loading multiple 3rd party widgets asynchronously
(function() {
var script,
scripts = document.getElementsByTagName('script')[0];
function load(url) {
script = document.createElement('script');
script.async = true;
script.src = url;
scripts.parentNode.insertBefore(script, scripts);
}
load('//apis.google.com/js/plusone.js');
load('//platform.twitter.com/widgets.js');
load('//s.widgetsite.com/widget.js');
}());
@wesleyvicthor
Copy link

common approach.

@zenorocha
Copy link
Author

How about now?

@harry1989
Copy link

Shouldn't

}());

be

})(); ?

@thefrontender
Copy link

@harry1989 Both are valid Javascript. But if you want an opinionated answer, try Crockford http://www.youtube.com/watch?v=taaEzHI9xyY&feature=youtu.be#t=33m39s

@jswebschmiede
Copy link

i use a window onload version. look https://gist.github.com/jswebschmiede/3660918

@coljung
Copy link

coljung commented Mar 30, 2013

Similar to this one: https://gist.github.com/necolas/1025811 , although i find that one much better.

@franklinjavier
Copy link

How about to pass the "document" as parameter into scope?

@mingyun
Copy link

mingyun commented Nov 9, 2013

good

@3runoDesign
Copy link

goood

@kimmykuang
Copy link

i think pass 'document' into scope is better

@fer-ri
Copy link

fer-ri commented May 15, 2015

Nice 👍

@PokemonAshLovesMyTurkeyAndILikeYouTwo

ty babe

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