I have a nodejs10 application that is deployed to Google App Engine. If a user has previously used the app in Chrome, the app does not work when the app is redeployed. The app is created with create-react-app and built with webpack so css and js are renamed on build but the index.html that references those files is not. So when the user access the site after deploy it will get the cached index.html that references js/css-files that does not exist anymore. This in turn causes Uncaught syntax error: unexpected token '<'
The only way I have found to get the app working again is to open inspector, disable cache and reload the page. Needless to say, this is not something you can ask the end user to do.
I have searched for a solution for this and found similar problems but not exactly the same, or if they are the same there is no solution available.
The express code serves index.html with res.sendFile
when the request is not made to an existing static file to make React router work properly:
app.get('*', (req,res) =>{
try {
res.sendFile(path.join(public+'/index.html'))
} catch(e) {
res.status(404).send()
}
});
The thing is I recently moved the app from a personal google cloud account to my business account, and I have never had this problem before. So either I have changed something to cause this, or App Engine has changed.
The response headers (response code 304) looks like:
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Content-Encoding: gzip
Content-Length: 1200
Content-Type: text/html; charset=UTF-8
Date: Thu, 03 Sep 2020 20:43:51 GMT
ETag: W/"967-49773873e8"
Last-Modified: Tue, 01 Jan 1980 00:00:01 GMT
Server: Google Frontend
Vary: Accept-Encoding
X-Cloud-Trace-Context: 7f98678c2ba7dc90ad204b67bec766df;o=1
X-Powered-By: Express
So as you can see the "Last-modified" date on the file is Jan 1, 1980. And I have verified that the file actually has that last modified date on app engine. But in the local build folder that is deployed, the file has a current date. Don't know if this is what is causing the problem though.
So I'm kind of lost. I guess I could hack the "last modified" header, but that does not feel like like it's a good solution. And I am also concerned the the same behavior could happen on other files that will cause similar problems. Anybody else run into this that came up with a solution?