조사 결과 모든 브라우저가 동일한 방식으로 HTTP 캐시 지시문을 준수하는 것은 아닙니다.
보안상의 이유로 우리는 웹 브라우저 에서 애플리케이션의 특정 페이지를 캐시하는 것을 절대 원하지 않습니다 . 이것은 최소한 다음 브라우저에서 작동해야 합니다.
인터넷 익스플로러 6+
파이어폭스 1.5 이상
사파리 3+
오페라 9+
크롬
우리의 요구 사항은 보안 테스트에서 나왔습니다. 당사 웹사이트에서 로그아웃한 후 뒤로 버튼을 눌러 캐시된 페이지를 볼 수 있습니다.
PHP 사용:
header("Cache-Control: no-cache, no-store, must-revalidate"); / / HTTP 1.1 .
header("Pragma: no-cache"); / / HTTP 1.0 .
header("Expires: 0"); / / Proxies.
Java 서블릿 또는 Node.js 사용:
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); / / HTTP 1.1 .
response.setHeader("Pragma", "no-cache"); / / HTTP 1.0 .
response.setHeader("Expires", "0"); / / Proxies.
ASP.NET-MVC 사용
Response .Cache .SetCacheability (HttpCacheability.NoCache);
Response .Cache .AppendCacheExtension ("no-store, must-revalidate" );
Response .AppendHeader ("Pragma" , "no-cache" );
Response .AppendHeader ("Expires" , "0" );
ASP.NET 웹 API 사용:
response.Headers.CacheControl = new CacheControlHeaderValue
{
NoCache = true ,
NoStore = true ,
MustRevalidate = true
};
response.Headers.Pragma.ParseAdd ("no-cache" );
response.Content?.Headers.TryAddWithoutValidation ("Expires" , 0. ToString ());
ASP.NET 사용:
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); / / HTTP 1.1 .
Response.AppendHeader("Pragma", "no-cache"); / / HTTP 1.0 .
Response.AppendHeader("Expires", "0"); / / Proxies.
ASP.NET Core v3 사용
Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate" ;
Response.Headers[HeaderNames.Expires] = "0" ;
Response.Headers[HeaderNames.Pragma] = "no-cache" ;
ASP 사용:
Response.addHeader "Cache-Control", "no-cache, no-store, must-revalidate" ' HTTP 1.1.
Response.addHeader "Pragma", "no-cache" ' HTTP 1.0 .
Response.addHeader "Expires", "0" ' Proxies.
Ruby on Rails 사용:
headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1 .
headers["Pragma"] = "no-cache" # HTTP 1.0 .
headers["Expires"] = "0" # Proxies.
파이썬/플라스크 사용:
response = make_response(render_template(...))
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1 .
response.headers["Pragma"] = "no-cache" # HTTP 1.0 .
response.headers["Expires"] = "0" # Proxies.
Python/Django 사용:
response["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1 .
response["Pragma"] = "no-cache" # HTTP 1.0 .
response["Expires"] = "0" # Proxies.
파이썬/피라미드 사용:
request.response.headerlist.extend(
(
('Cache-Control' , 'no-cache, no-store, must-revalidate' ),
('Pragma' , 'no-cache' ),
('Expires' , '0' )
)
)
이동 사용:
responseWriter .Header ().Set ("Cache-Control" , "no-cache, no-store, must-revalidate" )
responseWriter .Header ().Set ("Pragma" , "no-cache" )
responseWriter .Header ().Set ("Expires" , "0" )
Clojure 사용(Ring utils 필요):
(require '[ring.util.response :as r])
(-> response
(r/header "Cache-Control" "no-cache, no-store, must-revalidate" )
(r/header "Pragma" "no-cache" )
(r/header "Expires" 0 ))
아파치 .htaccess파일 사용:
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
HTML 사용:
<meta http-equiv ="Cache-Control" content ="no-cache, no-store, must-revalidate" >
<meta http-equiv ="Pragma" content ="no-cache" >
<meta http-equiv ="Expires" content ="0" >
HTML 메타 태그 대 HTTP 응답 헤더
https://stackoverflow.com/questions/49547/how-do-we-control-web-page-caching-across-all-browsers
How do we control web page caching, across all browsers?
Our investigations have shown us that not all browsers respect the HTTP cache directives in a uniform manner. For security reasons we do not want certain pages in our application to be cached, eve...
stackoverflow.com