I'm serving Angular 2 application with nginx using location section this way:
location / { try_files $uri $uri/ /index.html =404; }
try_files directive tries to find the requested uri in root directory and if it fails to find one it simply returns index.html
How to disable caching of index.html file?
In the root web. config we specify that we don't want to the index. html to cache by setting the cache-control , Pragma and Expires request headers as well as the max-age to 0.
The index directive defines the index file's name (the default value is index.html ). To continue with the example, if the request URI is /images/some/path/ , NGINX delivers the file /www/data/images/some/path/index.html if it exists. If it does not, NGINX returns HTTP code 404 (Not Found) by default.
Found a solution using nginx named locations:
location / { gzip_static on; try_files $uri @index; } location @index { add_header Cache-Control no-cache; expires 0; try_files /index.html =404; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With