Web
[Nginx] javascript source not update
코린이예요
2019. 5. 29. 19:43
반응형
문제 : javascript 소스 수정 후 nginx 재시작 하여도 변경된 소스가 반영되지 않음.
구글 도구옵션에서 캐쉬 삭제 후 다시 리프레쉬 하면 소스가 반영됀다.
매번 캐쉬 삭제하지 않고 반영할 수 있는 방법을 찾아보자
/etc/nginx/nginx.conf
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
if ($cors = 'true') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
# required to be able to read Authorization header in frontend
#add_header 'Access-Control-Expose-Headers' 'Authorization' always;
}
원인 : 캐쉬 컨트롤로 인해서 신규 JS파일이 반영안되고 이전 JS파일이 그대로 남아있는것 같음
nginx config에서 아래 추가해준 후 구글 옵션에서 캐쉬를 삭제하여 실행해보니 소스가 즉각 반영되었다.
# kill cache add_header Last-Modified $date_gmt; add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; if_modified_since off; expires off; etag off; |
https://stackoverflow.com/questions/40243633/disable-nginx-cache-for-javascript-files
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# kill cache
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
if ($cors = 'true') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
# required to be able to read Authorization header in frontend
#add_header 'Access-Control-Expose-Headers' 'Authorization' always;
}
https://varvy.com/pagespeed/cache-control.html
반응형