Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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);
} else {
$.getJSON(url, function (data) {
log('Fetched data, saving to cache:', url);
window.localStorage[url] = JSON.stringify(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment