Created
May 14, 2012 12:17
-
-
Save corny/2693657 to your computer and use it in GitHub Desktop.
$.getScript with caching
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
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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original getScript already support the options object. Use this signature
$.getScript({
url: "foo.js",
cache: true
})