Skip to content

Instantly share code, notes, and snippets.

@abernier
Created August 13, 2011 21:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abernier/1144288 to your computer and use it in GitHub Desktop.
Save abernier/1144288 to your computer and use it in GitHub Desktop.
$.cacheFactory
$.cachedGetScript = $.cacheFactory(function(dfd, url) {
$.getScript(url).then(dfd.resolve, dfd.reject);
});
(function ($) {
$.cacheFactory = function (f) {
var cache = {};
return function (key, cb) {
if (!cache[key]) {
cache[key] = $.Deferred(function (dfd) {
f(dfd, key);
}).promise();
}
return cache[key].done(cb);
};
};
}(jQuery));
@abernier
Copy link
Author

abernier commented Sep 2, 2011

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