Skip to content

Instantly share code, notes, and snippets.

@rainyjune
Created December 28, 2012 03:31
Show Gist options
  • Save rainyjune/4394233 to your computer and use it in GitHub Desktop.
Save rainyjune/4394233 to your computer and use it in GitHub Desktop.
Asynchronously load and execute a script from a specified URL
// Asynchronously load and execute a script from a specified URL
function loadasync(url) {
var head = document.getElementsByTagName("head")[0]; // Find document <head>
var s = document.createElement("script"); // Create a <script> element
s.src = url; // Set its src attribute
head.appendChild(s); // Insert the <script> into head
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment