javascriptnginxsingle-page-applicationhttp-proxy

ngnix expires header using map doesnt work when reloading the page


I have a single page application app, where I don't want the index.html file to be cached (because then if there will be a new version the users won't get it as their browser will get the cached index.html that is linked to the old javascript file the bundler outputs).

I defined my template to look like so:

map $sent_http_content_type $expires {
 text/html epoch;
 default 1y;
}

server {
 listen $PORT;
 ...
 location / {
   add_header Access-Control-Allow-Origin *;
   try_files $uri /index.html;
   sendfile on;
   expires $expires;
   tcp_nopush on;
   gzip on;
   gzip_types text/html application/javascript text/css;
 }
 ...
}

When first loading the page the index.html the expires header is set correctly, but when doing a soft reload the expires date it set to one year. What could be the problem?

EDIT: I noticed that when first loading the page / hard reloading in the response headers of getting the index.html there is content-type text/html, but when reloading it this header simply isn't there, could that be the problem?


Solution

  • Well, found the answer on my own - the cache-control header should be used instead of the expires header.