Why is the "last-modified" incorrect on Google Cloud Platform App Engine?

Viewed 546

I deployed my web on Google Cloud Platform App Engine several times. Using the setting as follows:

app.yaml

runtime: nodejs10

Everything just worked fine when I tested it on the localhost. But when I deployed it to Google Cloud Platform. The response header always is showing last-modified: Tue, 01 Jan 1980 00:00:01 GMT. I have checked by [my-web].df.r.appspot.com to make sure that the problem is coming from Google Cloud Platform.

Does anyone have an idea?

Updated 2020-10-07
For anyone facing the same issue, please feel free to join the discussion here.

4 Answers

Apparently, this is behaviour by design as all timestamps are made zero on deploy by app-engine. see: https://issuetracker.google.com/issues/168399701

I was sending the static files myself using express. So I solved it by not setting the etag and last-modified headers. For example:

app.use("/", express.static(root, { etag: false, lastModified: false }));

Or for individual files:

app.get("/*", async (req, res) => {
  return res.sendFile("index.html", { root, lastModified: false, etag: false });
});

I had the same problem of old index.html being served. The problem was with the etag that was generated. Even though the files changed, the etag remained the same.

This caused the file to be served from browser's cache with status code 304. The culprit was my app.yaml file, which was

runtime: nodejs10

Changing it to below fixed the issue.

env: standard
runtime: nodejs10
default_expiration: '14d'

handlers:
  - url: /static
    static_dir: build/static
    secure: always

  - url: /(.*\.(json|ico))$
    static_files: build/\1
    upload: build/.*\.(json|ico)$
    secure: always

  - url: .*
    static_files: build/index.html
    upload: build/index.html
    expiration: '5s'
    secure: always

This seems to be a cache caused issue. To ensure that the new index.html is deployed, you would need to run “gcloud beta app deploy --no-cache”, additional fields may need to be added such as app.yaml as mentioned here. This would ensure that the new index.html associated with your version is pushed into the container.

We are experiencing the same issue that previous version of index.html are getting picked up by clients after redeploying an appengine standard app. This problem seemed to start mid-August. We initially found that adding a line to the client HTML file like: seemed to solve the problem. But this is no longer working.

Related