Skip to content

Instantly share code, notes, and snippets.

@kpuputti
Created June 22, 2011 13:49
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kpuputti/1040118 to your computer and use it in GitHub Desktop.
Save kpuputti/1040118 to your computer and use it in GitHub Desktop.
jQuery.getJSON abstraction to cache data to localStorage
var getCachedJSON = function (url, callback) {
var cachedData = window.localStorage[url];
if (cachedData) {
log('Data already cached, returning from cache:', url);
callback(JSON.parse(cachedData));
} else {
$.getJSON(url, function (data) {
log('Fetched data, saving to cache:', url);
window.localStorage[url] = JSON.stringify(data);
callback(data);
});
}
};
@vioKamran
Copy link

Thankyou

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