Dave Pruce

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromDave Pruce
ToMe
Subjectwindow.open but ignore the cache - possible??
Date18 January 2005 12:25
Hi
I have a web page that allows users to select a spreadsheet from a list
then click a button to open the selected sheet in a browser directly.
 
Now, for security reasons, I copy the spreadsheet to a temporary file and
open that. 
 
I have ~250 users, and store the temp file on the server (naturally) so I
build each users unique id no into the temp file name. The filename is then
attached to the button with an onclick.attribute.add in the codebehind file.
The button opens the file via window.open.
 
So, to the problem - unless the cache is flushed, the same file is always
taken from the cache rather than the recreated temp file from the server.
 
I am currently solving it by incorporating a random number based on 1000000
in the filename - better, but not 100%.
 
So ......... can javascript open a file directly from the server ignoring
the cache? (Got there finally)
 
Incidentally, you have a very readable website - thanks
 

Regards

Dave Pruce
FromMe
ToDave Pruce
SubjectRe: window.open but ignore the cache - possible??
Date18 January 2005 12:54
Dave,

Long question, short answer: no  ;)

For opening a new page, the only way to ensure it is not loaded from cache
using a script is to do what you are already doing; encode a random number
into the url.

Once the page is open, history.go(0) or location.reload() should refresh,
but location.reload(true) should force it to reload ignoring cache.

The alternative would be to send out the file with two additional HTTP
headers (assuming you have this level of access to the server):
Cache-Control: no-cache, must-revalidate
Pragma: no-cache

Browsers like Opera, Safari, Konqueror, OmniWeb, Shiira, etc, will ignore
these headers anyway and still use the cached version. So to summarise;
what you are doing is the most reliable way, although personally, I would
use
( new Date() ).getTime()
instead of the random number, as this number should update every
millisecond (that's the theory anyway).

As a completely unrelated point, you have a parsing error on your homepage.
IE hides it (it is visible in the source), but standards compliant browsers
display it at the top of the page:
<%@ Page language="VB" validateRequest="false" Inherits="dotIndex.Index"%>


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromDave Pruce
ToMe
SubjectRe: window.open but ignore the cache - possible??
Date18 January 2005 13:28
Hi Mark

Thanks for pointing out the error - bu**er me we've been trying to get our
websites to be Firefox compliant and didn't even think of ours!!

[Ed. Firefox is not the only Standards compliant browser. Opera, Mozilla,
Safari, Konqueror, OmniWeb, etc etc, have been in existence for many years
(Opera has been actively developed for about 10 years). They also show the
fault. And these should also be used for testing, not just the secondary
favourite browser of the day]

Back to the question: thanks for the explanation, its made things a bit
clearer, and good point about the random number, I'll change it.

Regards

Dave Pruce
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.