Skip to content

Instantly share code, notes, and snippets.

@richardkundl
Created November 1, 2013 17:56
Show Gist options
  • Save richardkundl/7269229 to your computer and use it in GitHub Desktop.
Save richardkundl/7269229 to your computer and use it in GitHub Desktop.
Simple way to caching AJAX request result
// define cache
var cache = {};
// ...
// within the AJAX callback
cache[url] = data;
// ...
// within callback that would set forth a request
if(cache[url]) {
// Explicitly call the callback, passing it the cached page data
return successCallback(cache[url]);
}
else {
// do all of the AJAX request and callback
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment