From d48fd5166184bb3f70b9e9eb392b83abd5fd1797 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Sat, 1 Nov 2014 14:30:29 +0000 Subject: [PATCH] change default for useFileCache. Fixes #2261 --- lib/less-browser/file-manager.js | 4 ++++ lib/less-browser/index.js | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/less-browser/file-manager.js b/lib/less-browser/file-manager.js index cf1cc503..680c45bb 100644 --- a/lib/less-browser/file-manager.js +++ b/lib/less-browser/file-manager.js @@ -80,6 +80,10 @@ FileManager.prototype.supports = function(filename, currentDirectory, options, e return true; }; +FileManager.prototype.clearFileCache = function() { + fileCache = {}; +}; + FileManager.prototype.loadFile = function loadFile(filename, currentDirectory, options, environment) { return new PromiseConstructor(function(fullfill, reject) { if (currentDirectory && !this.isPathAbsolute(filename)) { diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js index 0f38709d..ea32ee04 100644 --- a/lib/less-browser/index.js +++ b/lib/less-browser/index.js @@ -68,6 +68,10 @@ if (dumpLineNumbers) { options.dumpLineNumbers = dumpLineNumbers[1]; } +if (options.useFileCache === undefined) { + options.useFileCache = true; +} + var typePattern = /^text\/(x-)?less$/; function postProcessCSS(styles) { @@ -108,10 +112,6 @@ function loadStyles(modifyVars) { var lessText = style.innerHTML || ''; instanceOptions.filename = document.location.href.replace(/#.*$/, ''); - if (modifyVars || instanceOptions.globalVars) { - instanceOptions.useFileCache = true; - } - /*jshint loopfunc:true */ // use closure to store current style less.render(lessText, instanceOptions) @@ -138,9 +138,6 @@ function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) { if (modifyVars) { instanceOptions.modifyVars = modifyVars; } - if (modifyVars || options.globalVars) { - instanceOptions.useFileCache = true; - } fileManager.loadFile(sheet.href, null, instanceOptions, environment) .then(function loadInitialFileCallback(loadedFile) { @@ -198,6 +195,7 @@ function initRunningMode(){ if (less.env === 'development') { less.watchTimer = setInterval(function () { if (less.watchMode) { + fileManager.clearFileCache(); loadStyleSheets(function (e, css, _, sheet, context) { if (e) { errors.add(e, e.href || sheet.href); @@ -258,6 +256,9 @@ less.modifyVars = function(record) { }; less.refresh = function (reload, modifyVars) { + if (reload) { + fileManager.clearFileCache(); + } return new Promise(function (resolve, reject) { var startTime, endTime, totalMilliseconds; startTime = endTime = new Date();