Skip to content

Instantly share code, notes, and snippets.

View vioKamran's full-sized avatar
💭
I may be slow to respond.

Kamran Karimi vioKamran

💭
I may be slow to respond.
View GitHub Profile
@vioKamran
vioKamran / gist:f3b05e1dd789f72f6df30746f06761bf
Created April 22, 2023 14:08 — forked from kpuputti/gist:1040118
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);