0

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
Marbo
  • 45
  • 9

1 Answers1

0

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

saccodd
  • 972
  • 9
  • 23
  • I already use versioning on my files with webpack, so I don't think waiting for the files to expire changes anything. Thanks for the input though – Marbo Jul 01 '19 at 21:47
  • Unfortunately I'm not experienced with Laravel. Is it possible that its middleware is kinda 'overriding' your setup for Nginx? See: [here](https://itnext.io/laravel-the-hidden-setcacheheaders-middleware-4cd594ba462f) and [here](https://stackoverflow.com/questions/51821563/laravel-5-5-how-to-set-cache-control-http-header-globally) – saccodd Jul 04 '19 at 11:15