-
-
Save zarza/5d06f0138fafb6891c2dedf97a8a89db to your computer and use it in GitHub Desktop.
jQuery: Load external scripts and cache them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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