Skip to content

Instantly share code, notes, and snippets.

@zarza
Forked from jasondmoss/ajax-cache-include.js
Created November 17, 2018 06:12
Show Gist options
  • Save zarza/5d06f0138fafb6891c2dedf97a8a89db to your computer and use it in GitHub Desktop.
Save zarza/5d06f0138fafb6891c2dedf97a8a89db to your computer and use it in GitHub Desktop.
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