Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I invalidate a page in the browser cache from the client side?

I need the client (using javascript) to invalidate a page it has and essentially fetch a new version?

I thought I could do it all with headers: Invalidating cached content, If-Modified Headers?

If there NO way to have the browser refresh its current cached version, with out making a new request (via a new URL) ... so that the same original URL request could be used to see the updated content?

like image 228
farinspace Avatar asked Dec 04 '22 14:12

farinspace


2 Answers

If you want to reload the current page you can do:

location.reload(true);

Otherwise the "traditional" way is to add a random querystring onto the end

'...?rnd=' + Math.random();
like image 183
Greg Avatar answered Dec 26 '22 08:12

Greg


You can't do that with javascript, to solve your problem or use method POST instead of GET or use nocache random parameter trick:

If you want more information, see: Is it possible to cache POST methods in HTTP?

like image 25
Cleiton Avatar answered Dec 26 '22 08:12

Cleiton