I work on a web application in ASP.NET and HTML5. I have a simple page Default.aspx. In its Page_Load handler I call 'Response.Redirect("xxx.aspx"). I also defined a manifest file, Default.appcache as I want my application to work offline (in such case I javascript methods are used for redirection). Browser cached the page as expected but a problem occured - even though server is online, browser uses the cached page. When user enters Default.aspx no call is sent to server. How can I prevent this behavior? I would like the browser to send a normal request to IIS if it is online and use cached page only when server doesn't respond. I would be grateful for all suggestions.
1 Answer
You can't, pages in the cache are always served from the cache. The only way to update them is update the manifest and force new versions to be downloaded.
If you want one page to be served when online and a different one when offline then you should investigate the FALLBACK section of the manifest. Note that the page which references the manifest is always cached, so you need to set the fallback up on a different pair of pages.
3 Comments
Rummy
Thanks for answering :) But your answer is kind of shocking... I have a page which retrieves users from database and displays them as a list. Content of the database can be changeg anytime, so when application is online I would like to call the server and get fresh data. In offlne mode, however, I would like to display the list from the last visit. According to your answer I should create two identical pages - one would be called normally, second would be used for FALLBACK. Strange :| I'm wondering if this can be done with url rewriting...
robertc
Changing data shouldn't be part of your application cache. Retrieve it with Ajax and put it in local storage.
Rummy
In the end I had to deal with the situation just as you said - get data with a callback and store locally.