Skip to content

Instantly share code, notes, and snippets.

@takahiro47
Last active September 9, 2016 16:10
Show Gist options
  • Save takahiro47/70a5fd4a9bf2449590497425d2d67ebf to your computer and use it in GitHub Desktop.
Save takahiro47/70a5fd4a9bf2449590497425d2d67ebf to your computer and use it in GitHub Desktop.
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
// For quickly trying things out in the browser, jQuery and Lo-Dash (like Underscore.js) are great.
// Read the code below (never copy & paste code you don't trust),
// then you can copy & paste it into the browser console to load jQuery & lodash.
(function () {
var jq = document.createElement('script');
jq.src = 'https://code.jquery.com/jquery-2.1.4.js';
document.getElementsByTagName('head')[0].appendChild(jq);
// jQuery should be available via "jQuery" (and we'll set up the $ alias in the defer() function)
var ld = document.createElement('script');
ld.src = 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js';
document.getElementsByTagName('head')[0].appendChild(ld);
// lodash should be available via "_".
var defer = function () {
if (window.jQuery) {
jQuery.noConflict();
$ = jQuery;
// jQuery should be available via "$".
} else {
setTimeout(function () {
defer();
}, 50);
}
};
defer(); // wait for jQuery to download, then set up $ alias
console.log('jQuery ($) and lodash (_) should now be available in your browser console.');
console.log('If not, there may be a Content Security Policy error.');
console.log('See: https://jquery.com https://lodash.com for documentation.')
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment