Skip to content

Instantly share code, notes, and snippets.

@ashmind
Created February 1, 2014 08:05
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 ashmind/8749472 to your computer and use it in GitHub Desktop.
Save ashmind/8749472 to your computer and use it in GitHub Desktop.
// https://gist.github.com/ashmind/8749472
// jQuery plugin to load JS files from GitHub.
// NOT FOR PRODUCTION, use something like Bower instead.
// This is for quick iteration sites like CodePen or JSFiddle.
(function($) {
// this API requires blob SHA. get the SHA by requesting
// https://api.github.com/repos/:owner/:repo/contents/:path
$.loadScriptsFromGitHub = function(scripts, success) {
loadNextScript(scripts.slice(0), success || function() {})
}
function loadNextScript(scripts, allSuccess) {
var script = scripts.pop();
if (!script) {
allSuccess();
return;
}
var fullUrl = 'https://api.github.com/repos/'
+ script.owner + '/' + script.repo
+ '/git/blobs/' + script.sha;
$.ajax(fullUrl, {
headers: {
Accept: 'application/vnd.github.v3.raw'
},
success: function(scriptBody) {
eval.call(window, scriptBody);
loadNextScript(scripts, allSuccess);
}
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment