Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery: Load external scripts and cache them.
/**
* Cache AJAX-included scripts.
*/
$.cachedScript = function (url, options) {
options = $.extend(
options || {}, {
dataType: "script",
cache: true,
url: url
}
);
return $.ajax(options);
};
/* ------------------- */
// Usage.
var myScript = siteUrl +"/js/my-script.js";
$.cachedScript(myScript).done(
function (script, textStatus) {
console.log(myScript +": "+ textStatus);
}
);
/* <> */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment