NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: Poul Jensen on May 12, 2025, 12:32:44 AM

Title: Avoid downloaded file been served from browser cache (SOLVED)
Post by: Poul Jensen on May 12, 2025, 12:32:44 AM
Hi,

Using this to download a file:
Code: [Select]
p_web.HeaderDetails.ContentDisposition =  'attachment; filename="'& CLIP(Loc:DownloadFileName) &'"'
Works fine first time, but if user later downloads same file, it is being served from internet browsers cache, and therefore not the latest version af the file.

How can I avoid this?

tia
/Poul
Title: Re: Avoid downloaded file been served from browser cache
Post by: Bruce on May 13, 2025, 06:44:16 AM
first you need to determine if it's coming from the local client cache, or the server cache.
(Both the browser, like Chrome or Edge) and the NetTalk server can cache files.

There are headers you can set when serving the file to indicate it's uncacheable. (You can google for that if you like, or look in netweb.clw.)
Alternatively you can alter the URL - by adding a random parameter. For example;

capesoft.com\somefile.saf?r=123
is different from
capesoft.com\somefile.saf?r=321

So simple by adding a parameter (which the server happily ignores) with a random value, the client won't get it from cache.
Obviously though it depends on how they are seeing the URL in the first place to download the file.

Cheers
Bruce
Title: Re: Avoid downloaded file been served from browser cache
Post by: Bruce on May 13, 2025, 06:45:39 AM
try
    p_web.HeaderDetails.ContentDisposition =  'attachment; filename="'& CLIP(Loc:DownloadFileName) &'"'
    p_web.HeaderDetails.CacheControl = 'no-store, no-cache, must-revalidate, private,post-check=0, pre-check=0, max-age=0'

Title: Re: Avoid downloaded file been served from browser cache
Post by: Poul Jensen on May 13, 2025, 07:02:50 AM
try
    p_web.HeaderDetails.ContentDisposition =  'attachment; filename="'& CLIP(Loc:DownloadFileName) &'"'
    p_web.HeaderDetails.CacheControl = 'no-store, no-cache, must-revalidate, private,post-check=0, pre-check=0, max-age=0'


Thanks Bruce - this did it.

/Poul