'Angular and Nginx - no cache for index and assets
I am running angular app on Nginx server and I was trying to add no-cache header for index.html and all files in single directory in assets: /assets/i18n/*
Here's my current config:
server {
listen 80;
sendfile on;
default_type application/octet-stream;
gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 1100;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;
client_header_buffer_size 10m;
large_client_header_buffers 4 10m;
root /usr/share/nginx/html/;
location / {
try_files ${DOLLAR}uri ${DOLLAR}uri/ /index.html =404;
}
...other setup for rest and auth
}
I was trying to achieve this by adding for assets:
location /assets/i18n {
expires -1;
add_header "Cache-Control" "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"
}
but still I have to somehow redirect this request to angular directory because I will not get assets in such case.
For the index.html I was trying to add this in such way:
location / {
try_files ${DOLLAR}uri ${DOLLAR}uri/ /index.html =404;
expires -1;
add_header "Cache-Control" "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"
}
but this will add such header for all other files which I want to avoid.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
