mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
abstract localStorage a little
This commit is contained in:
@@ -43,6 +43,7 @@ if (less.env === 'development') {
|
||||
less.optimization = 3;
|
||||
}
|
||||
|
||||
var cache = (typeof(window.localStorage) === 'undefined') ? null : window.localStorage;
|
||||
|
||||
//
|
||||
// Select all links with the 'rel' attribute set to "less"
|
||||
@@ -77,8 +78,8 @@ function loadStyleSheets(callback, async) {
|
||||
}
|
||||
|
||||
function loadStyleSheet(sheet, callback, async) {
|
||||
var css = typeof(localStorage) !== "undefined" && localStorage.getItem(sheet.href);
|
||||
var timestamp = typeof(localStorage) !== "undefined" && localStorage.getItem(sheet.href + ':timestamp');
|
||||
var css = cache && cache.getItem(sheet.href);
|
||||
var timestamp = cache && cache.getItem(sheet.href + ':timestamp');
|
||||
var styles = { css: css, timestamp: timestamp };
|
||||
|
||||
xhr(sheet.href, async, function (data, lastModified) {
|
||||
@@ -140,9 +141,9 @@ 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, styles);
|
||||
localStorage.setItem(sheet.href + ':timestamp', lastModified);
|
||||
if (lastModified && cache) {
|
||||
cache.setItem(sheet.href, styles);
|
||||
cache.setItem(sheet.href + ':timestamp', lastModified);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user