0
votes

I'm building a laravel application and I'm trying to enable browser caching.

I tried to set expires/cache-control in a custom nginx-app.conf file located in my application root. (https://cloud.google.com/appengine/docs/flexible/php/reference/app-yaml)

Content of nginx-app.conf:

location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv|svgz?|ttf|ttc|otf|eot|woff|woff2) {
  expires 30d;
  add_header Pragma public;
  add_header Cache-Control "max-age: 2592000,public";
}

But the headers still contain the default cache-control of 600 seconds from google.

cache-control: max-age=600
cache-control: public
content-encoding: gzip
content-type: text/css
date: Fri, 14 Jun 2019 10:19:07 GMT
etag: W/"5d03719d-6ffe"
expires: Fri, 14 Jun 2019 10:29:07 GMT
last-modified: Fri, 14 Jun 2019 10:06:21 GMT
server: nginx
status: 200
vary: Accept-Encoding
via: 1.1 google
1

1 Answers

0
votes

I had similar problems with caching in Nginx on GAE flex and I was not able to find a fix on the reverse proxy.

My guess is that you have to wait for those files to expire and then you'll see the new cache-control.

I find GAE very limiting from this point of view, didn't experience this situation on AWS for example.

A workaround at the application layer is

  1. cache busting / versioning of the static files (you can see this example for Sails.js)
  2. adding cache headers to requests (same link, following comment)

See also this answer