Created
November 1, 2013 17:56
-
-
Save richardkundl/7269229 to your computer and use it in GitHub Desktop.
Simple way to caching AJAX request result
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
// 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