Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Destroy the localStorage copy of less.js client-side-generated CSS
// Destroys the localStorage copy of CSS that less.js creates
function destroyLessCache(pathToCss) { // e.g. '/css/' or '/stylesheets/'
if (!window.localStorage || !less || less.env !== 'development') {
var host =;
var protocol = window.location.protocol;
var keyPrefix = protocol + '//' + host + pathToCss;
for (var key in window.localStorage) {
if (key.indexOf(keyPrefix) === 0) {
delete window.localStorage[key];
Copy link

ianferrell commented Nov 13, 2013

Anyone have a better solution than this? I'm running chrome with the cache disabled, but ideally the development environment should work as expected.

Copy link

yllumi commented Aug 27, 2014

I've tried this code, but my template still using the less files. The error shown "Uncaught ReferenceError: less is not defined". Anyone can help? It is frustating hahaha~

Copy link

abcarroll commented Apr 4, 2015

I've included this modified / improved version:

In my project here:

Thanks a ton for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment