views:

551

answers:

4

It is well and good that the server restarts automatically for each change in the code. How would you have even the browser refresh automatically, as per configuration (Turn on and off, the least).

How to do it on Windows, and on Linux, for all different development frameworks.

What existing packages allow you to do it, and if you are to just add a browser.refresh at each runserver, how would you do it.

+4  A: 

On Mac OS X you can do that using AppleScript. I did that some time ago and been using it ever since.

# Check if Firefox is running, if so refresh
ps -xc|grep -sqi firefox && osascript <<'APPLESCRIPT'
tell app "Firefox" to activate
tell app "System Events"
   keystroke "r" using {command down}
end tell
APPLESCRIPT

# Check if Safari is running, if so refresh
ps -xc|grep -sq Safari && osascript -e 'tell app "Safari"' -e 'activate' \
-e 'do JavaScript    "window.location.reload();" in first document' -e 'end tell'

It refreshes Safari and Firefox, but as I said, it only works the mac. I've been using it on Textmate, this way every time I save a django file I also refresh the browsers. Pretty handy, but also slightly annoying when reading docs online and writing code, hehe.

Edu Felipe
Awesome! Same can be customized for *nix as well
Lakshman Prasad
A: 

There are several ways to have a browser auto-refresh. The easiest is to conditionally generate the meta tag

<meta http-equiv="refresh" content="15" />

To cause the browser to refresh after 15 seconds.

The problem with auto-refresh during web development is that just as you notice something slightly odd about your page and are taking a closer look... AAAARRGGH! STOP!!! If you're lucky, you'll get the same page with the same problem.

Dave W. Smith
A: 

The Opera browser has a built-in option to auto-refresh pages.

Anyway, you need to tell the client when it can refresh (and the client can ignore). You can tell it in 2 ways:

  • The meta tag refresh
  • javascript.location and setTimeOut

Now, more specifically to your question, http is a stateless protocol. When the server finishes sending data, it's over. The server can't say "Hey here's more data, browser!", therefore won't tell the browser when it has restarted itself.

You could implement an Ajax/Coment call (to get more data), but that would be like cheating, because you're going to make more requests with the client, therefore it's not a lonely server job.

inerte
+1  A: 

For Firefox there is the ReloadEvery Add-On that let's you specify at what intervals to reload the page.

Lorenz