I'm doing a project in Django and using djangos-css () and Sass (/). 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?
I'm doing a project in Django and using djangos-css (http://github./dziegler/django-css) and Sass (http://sass-lang./). 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?
Share Improve this question edited Jan 31, 2010 at 0:30 hekevintran asked Jan 30, 2010 at 20:43 hekevintranhekevintran 23.7k34 gold badges116 silver badges182 bronze badges2 Answers
Reset to default 3The simplest way is usually to add a unique parameter onto the url, I often just use a timestamp
var timestamp = (new Date()).getTime();
url += '?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.
Not all caches will cache content with a query string.
Steve Souders remends, “…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