views:

199

answers:

1

I'm doing a project in Django and using djangos-css (http://github.com/dziegler/django-css) and Sass (http://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?

+1  A: 

The 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.

Rob Van Dam
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 (http://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
I found XRefresh (http://xrefresh.binaryage.com/) which solves this problem better than using JavaScript.
hekevintran