Skip to content

Instantly share code, notes, and snippets.

@marr
Created May 22, 2011 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marr/985531 to your computer and use it in GitHub Desktop.
Save marr/985531 to your computer and use it in GitHub Desktop.
var filename = "https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js";
test("Lazy-load jQuery", function()
{
stop(3000);
loadScript(filename, function() {
start();
ok(/loaded|complete/.test(document.readyState), "document is complete");
ok(typeof $ == "function", "$ is a function");
ok(typeof jQuery == "function", "jQuery is a function");
});
});
function loadScript(filename, callback)
{
var script = document.createElement('script')
script.setAttribute("type","text/javascript")
script.setAttribute("src", filename)
if (typeof script!="undefined")
document.getElementsByTagName("head")[0].appendChild(script);
var interval = setInterval(function()
{
if (/loaded|complete/.test(document.readyState))
{
clearInterval(interval);
callback();
}
}, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment