Skip to content

Instantly share code, notes, and snippets.

@corny
Created May 14, 2012 12:17
Show Gist options
  • Save corny/2693657 to your computer and use it in GitHub Desktop.
Save corny/2693657 to your computer and use it in GitHub Desktop.
$.getScript with caching
jQuery.getCachedScript = function(url, callback, options) {
// allow user to set any option except for dataType, cache, and url
options = jQuery.extend(options || {}, {
dataType: "script",
cache: true,
url: url,
complete: callback || jQuery.noop
});
// Use jQuery.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax(options);
};
@oriadam
Copy link

oriadam commented Jul 5, 2017

The original getScript already support the options object. Use this signature
$.getScript({
url: "foo.js",
cache: true
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment