use two fields for cache, so we don't need to parse JSON

This commit is contained in:
cloudhead
2010-06-14 21:08:11 -04:00
parent 0d98d2401a
commit 4135ccf010

View File

@@ -67,7 +67,8 @@ function loadStyleSheets(callback) {
function loadStyleSheet(sheet, callback) {
var css = typeof(localStorage) !== "undefined" && localStorage.getItem(sheet.href);
var styles = css && JSON.parse(css);
var timestamp = typeof(localStorage) !== "undefined" && localStorage.getItem(sheet.href + ':timestamp');
var styles = { css: css, timestamp: timestamp };
xhr(sheet.href, function (data, lastModified) {
if (styles && (new(Date)(lastModified).valueOf() ===
@@ -123,7 +124,8 @@ function createCSS(styles, sheet, lastModified) {
// Don't update the local store if the file wasn't modified
if (lastModified && typeof(localStorage) !== "undefined") {
localStorage.setItem(sheet.href, JSON.stringify({ timestamp: lastModified, css: styles }));
localStorage.setItem(sheet.href, styles);
localStorage.setItem(sheet.href + ':timestamp', lastModified);
}
}