-
-
Save abcarroll/8c96eb0cbfce280e6bf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This clears the LESS.js cache, since it aggressively caches @import statements. | |
* Credit: Attaboy, https://gist.github.com/attaboy/1346280 | |
* Additional key checks and debugging output by A.B. Carroll. (http://github.com/nezzario) | |
* License: Assumed MIT/BSD-like license, please give credit where credit is due. | |
*/ | |
less.env = 'development'; | |
console.log("If you are seeing this in a production environment you are likely doing something wrong or forgot to remove the destroyLessCache() script."); | |
function destroyLessCache(pathToCss) { // e.g. '/css/' or '/stylesheets/' | |
if (!window.localStorage || !less || less.env !== 'development') { | |
console.log('destroyLessCache(): Not destroying cache. Either no local storage, LESS not loaded, or less.env not set to development'); | |
return; | |
} | |
var host = window.location.host; | |
var protocol = window.location.protocol; | |
var keyPrefix = protocol + '//' + host + pathToCss; | |
for (var key in window.localStorage) { | |
if (key.indexOf(keyPrefix) === 0 && (key.indexOf('.less', key.length - 5) !== -1 || key.indexOf('.less:timestamp', key.length - 15) !== -1)) { | |
console.log('Deleted LESS Cache Key: ' + key); | |
delete window.localStorage[key]; | |
} | |
} | |
} | |
// You MUST put any path that contains LESS files that are being compiled here as separate function calls (or just add '/' if you feel it's safe). | |
destroyLessCache('/css/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment