4

I'm trying to get a page to load a fresh copy from server when the client arrives at it by hitting the back button. By default it loads the old cached copy from browser memory.

Is there a way to do that? (in node.js)

Adding an empty function to window.unload as mentioned here doesn't work for me.

Community
  • 1
  • 1
laggingreflex
  • 32,948
  • 35
  • 141
  • 196

2 Answers2

6

Tried all the Meta tags, they have no effect. But the question referred to by @BenJ mentions "when you don't have access to the web server's headers".. I actually do have access to and can set whatever headers from server-side. SO I dug out this answer which worked flawlessly

res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
Community
  • 1
  • 1
laggingreflex
  • 32,948
  • 35
  • 141
  • 196
  • I tried this with res.redirect --> it does not seem to work on Chrome Version 61. router.get('/logout', function (req, res) { res.cookie('jwtToken', '', {expires: new Date(0)}); res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate'); res.header('Expires', '-1'); res.header('Pragma', 'no-cache'); res.redirect('/vendor/login'); }); – j10 Oct 03 '17 at 09:08
0

have you tried using these in the <head> section of your page:

<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />

Update

refer to this question on SO: Using <meta> tags to turn off caching in all browsers?

Community
  • 1
  • 1