1

Note: I cannot change the client as it is cached however /api is not cached.

I have a Cache Control header of a year for the main html and javascript of my page. When releasing a new version, clients will not update because the cache policy is too long. While I have adjusted the cache policy for future visits, existing users will not update until they hard refresh their page.

This means I cannot change the client code (it's cached), but I can change the responses from /api as the /api/* path is not cached.

The client sends a build number to the server which the server can use to determine which version of the client made the request.

If on the /api/login endpoint I intercept the request and check the build number to see if it's current, can I respond to the request with some kind of status code telling the browser to hard refresh?

For instance am I able to do something like this:

app.post('/api/login', (req, res) => {
  // add a check that responds with a 302 to the current page if the build number is old
  if (req.headers['x-app-buildno'] !== 'latest build no') {
    res.setHeader('localtion', req.headers.host)
    res.sendStatus(302)
    return
  } 
  // normal logic
})
David Alsh
  • 6,747
  • 6
  • 34
  • 60
  • 2
    No, there isn't. If the browser is using the cache, it won't make the request in the first place. – Barmar Jul 08 '21 at 00:33
  • 1
    Use WebSockets or Long Polling. – Praveen Kumar Purushothaman Jul 08 '21 at 00:34
  • `/api/*` is not cached so the response can be adjusted to help. I am using WebSockets in a future version, however I need the clients to update to use it. – David Alsh Jul 08 '21 at 00:43
  • I wish I could downvote the WebSockets answer, it provides no help whatsoever but distracts people from the main question. I am very interested on how to deal with this situation, I am having the very same problem as you @Barmar – enanone May 09 '22 at 12:14

0 Answers0