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
})