Using JavaScript to invalidate the browser's cache?

The simplest way is usually to add a unique parameter onto the url, I often just use a timestamp.

Up vote 3 down vote favorite 1 share g+ share fb share tw.

I'm doing a project in Django and using djangos-css (github.com/dziegler/django-css) and Sass (sass-lang.com/). The Sass files are served in development using django-css. I want to write a JavaScript routine that will every one second retrieve the CSS assets.

The purpose of this is so that the designer can edit the Sass files, hit save, and see the result in the browser immediately without switching applications and hitting refresh. Basically I need a way for JavaScript to force the browser to re-download certain files without doing a page refresh. Is this possible?

Javascript css web-development caching sass link|improve this question edited Jan 31 '10 at 0:30 asked Jan 30 '10 at 20:43hekevintran2,15911347 80% accept rate.

Time=' + timestamp; Just be careful if your requests already have parameters then you need to add &time=' + timstamp instead. The browser can't cache the request because each request looks unique.

Your technique works. I put it inside a call to setInterval. The problem I am having now is that every time the browser redraws using the new CSS files, it flashes.

This quick flashing is extremely annoying. I suppose that there probably is no way to stop it. There is an app called CSSEdit (macrabbit.com/cssedit) that allows you to edit CSS with a live preview in a Webkit view without the flashing.

Unfortunately this app does not support Sass or languages like it. Maybe the answer is to write a custom minimal browser? – hekevintran Jan 31 '10 at 1:42 1 I found XRefresh (xrefresh.binaryage.com) which solves this problem better than using JavaScript.

– hekevintran Jan 31 '10 at 6:11.

Not all caches will cache content with a query string. Steve Souders recommends, “…avoiding a querystring for cacheable resources”. He found that in this case 5-20% of requests will not be cached.

Query strings in particular do not work at all with some CDNs for cache invalidation. The better way is to generate a MD5 with the javascript file name for each release e.g. {path to script file}/filename-{md5 hash}.js.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions