Thursday, January 29, 2009

Window.open displays the cached version of page

Window.open JavaScript function inherently opens the cached version of the page requested. For the first time the web page will be brought from the server, but for subsequent requests it will display the cached version of the page that was bought first. How to avoid this..?

Window.open shows the cached version of the page ONLY if the URL requested matches the cached page URL. The best option is to change the URL every time you try to use the window.open statement. This can be achieved by two methods:

  1. Append a dummy queryString with Random value
  2. Append a dummy queryString with DateTime stamp
Out of the two the second method is most reliable, since the DateTime stamp will be unique every time you invoke the window.open statement. Example:

var dt = new Date().toString();
var URLToOpen = 'http://server.com/page1.aspx?TimeStamp=' + dt;
window.open('New Page','',URLToOpen);
Your comments are welcome.

0 comments:

Post a Comment