Skip to content

Instantly share code, notes, and snippets.

@attaboy
Created November 7, 2011 21:40
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save attaboy/1346280 to your computer and use it in GitHub Desktop.
Save attaboy/1346280 to your computer and use it in GitHub Desktop.
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') {
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) {
delete window.localStorage[key];
}
}
}
@jasonrhodes
Copy link

Strangely, Google Chrome seems to aggressively cache the Less files even with { env: "development" } set. @jenwachter and I have had no luck figuring out why.

@shankarcabus
Copy link

I'm with the same problem in the Chrome! After the version 29 update, this script stopped working.
For now, I disabled the cache of Chrome: Devtools > General> Disable cache

@ianferrell
Copy link

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

@yllumi
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~

@abcarroll
Copy link

I've included this modified / improved version:
https://gist.github.com/nezzario/8c96eb0cbfce280e6bf6

In my project here:
http://www.github.com/nezzario/kickoff

Thanks a ton for this!

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