views:

283

answers:

6

I remember watching a jquery demo by John Resig. He had a browser application that reloaded live while he was coding. I think he did not even have to save his code changes for this to happen ( see 3:40 in the video ).

This is the video: http://vimeo.com/116991

I find this really cool and think this can be really useful and fun while you are coding.

Do you know what application he was using? Do you know how this is done or might be done?

Update: This was suggested by Januz:

You could use XRefresh. It reloads everytime you save a file in your project's folder.

Seems to work fine.

+3  A: 

Skúli - I don't have the time to watch the whole video but I think I know what you are after: the ability to refresh a web page automatically. This can be done for any number of reasons. You might want to implement a monitor, save content, avoid timeouts, etc.

While JQuery can be useful, the overall effect is achieved using Ajax. In ASP.NET, simply place a timer on the page and a matching Ajax update panel:

<asp:Timer ID="Timer1" runat="server" Interval="60000" ontick="Timer1_Tick" ></asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"/>
    </Triggers>
</asp:UpdatePanel>

In the callback, you can save the state of the page (e.g. a document the user is working on) or refresh content in the update panel (there is no content shown in the panel here but I think you'll get the idea).

Mark Brittingham
Regardless of the server side language he is using, the effect is always achieved using ajax :)
Andreas Bonini
If you have a client side state. For example you are filling in a form I think you will always loose that state when the page is reloaded. That is why I think it is loaded when you change your code. In the video, when he is showing the page he is making it does not seem to reload. Othervise he could not show the page properly.Can this be acchieved by only reloading if the body of the page does not have focus? I think so.
Skúli
Andeas - you are right and my language was pretty awkward. I was changing it as you commented! Skuli - one of the reasons that Ajax is so cool is that is *won't* look like the page is reloading. Technically, it isn't - just a part of it is. And no, you do not lose the state of the page during an asynchronous callback. In fact, the state of the page (in ASP.NET anyway) is sent back for use by the server. Lastly - this has nothing to do with focus or whether the body has focus.
Mark Brittingham
Could whoever clicked to downvote this answer please explain? Is there something you think I'm missing that could help Skúli solve his problem?
Mark Brittingham
-1 Because Resig *certainly* would not use ASP.NET AJAX to do anything
Josh Stodola
Can you use this without having to change the server side code while the page is developed?
Skúli
Josh - ummm, Ok. I wasn't aware that Resig disliked ASP.NET but, honestly, I was just trying to provide an answer that was likely to be helpful given the sheer number of people that use ASP.NET.Skuli - you wouldn't have to change the server side code, no. Also, I think that you'd be limited to making changes within the ContentTemplate as well (the other areas would not be updated). Of course, you could just put everything of interest in the ContentTemplate area until you had all of the kinks worked out.
Mark Brittingham
BTW - my assumption when you asked about changing code, though, was that you were working on the Server side. You should note that you'll lose the ASP.NET session after 6-8 refreshes if you are working on the server side or if you make a server side coding change that doesn't compile.
Mark Brittingham
A: 

I tried this javascript code:

window.setInterval("if(document.hasFocus()===false)location.reload(true);",3000);

It works in firefox, I get a warning in IE and it doesn't work in chrome( document.hasFocus() is alway true )

Not a perfect solution, but it works, though not gracefully. The downside is that this code is in the solution itself. Using ajax that can be fixed.

Skúli
A: 

I don't know what he uses, but I use ReloadEvery

David Dorward
+2  A: 

You could use XRefresh. It reloads everytime you save a file in your project's folder.

Januz
Cool. Seems to work nicely
Skúli
+1  A: 

You could also use a meta refresh to automatically reload the page:

<meta http-equiv="refresh" content="3" />
Vinz
A: 

He's using a code editor with a preview window that automatically refreshes on changes to the code window. No Ajax magic!

Not sure exactly what editor he's using but I know CSSEdit can do this, there's probably plugins for various other editors out there.

roryf