htaccess-클라이언트의 브라우저가 캐시를 지우도록 강제하는 방법은 무엇입니까?
내 사이트에는 다음과 같은 htaccess 규칙이 있습니다.
# BEGIN Gzip
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
# END Gzip
# BEGIN EXPIRES
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES
방금 내 사이트를 업데이트했는데 캐시를 지울 때까지 모두 엉망인 것처럼 보였습니다. 사용자가 변경 사항을 볼 수 있도록 업데이트 후 클라이언트의 브라우저가 캐시를 지우도록하려면 어떻게해야합니까?
브라우저가 무언가를 캐시하도록 강제 할 수 있지만
브라우저가 캐시를 지우도록 강제 할 수 없습니다.
따라서 유일한 (AMAIK) 방법은 리소스에 새 URL 을 사용하는 것 입니다. 버전 관리와 같은 것.
다른 답변에서 말했듯이 URL을 변경하는 것은 좋은 캐시 무효화 기술이지만 더 큰 사이트를 통해 모든 URL을 변경하고 파일을 이동하는 것은 많은 작업입니다.
유사한 기술은 임의의 문자열 / 번호 또는 버전 번호 인 URL 문자열에 버전 매개 변수를 추가하고 변경된 파일 만 대상으로하는 것입니다.
예를 들어 사이트 CSS를 변경하고 강제 새로 고침을 수행 할 때까지 이상해 보이는 ?ver=1.1
경우 파일 헤드에서 CSS 가져 오기에 추가 하기 만하면 됩니다. 브라우저에 대한 이것은 다른 파일이지만 파일의 실제 위치 나 이름이 아니라 가져 오기만 변경하면됩니다.
예 :
<link href="assets/css/style.css" rel="stylesheet" type="text/css" />
된다
<link href="assets/css/style.css?ver=1.1" rel="stylesheet" type="text/css" />
자바 스크립트 파일에서도 잘 작동합니다.
문제가 생겼어 ...
클라이언트 브라우저 캐시를 완전히 지울 수 있지만 최근 변경 사항이 클라이언트 브라우저에 반영되도록 애플리케이션에 일부 코드를 추가 할 수 있습니다.
귀하의 <head>
:
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
출처 : http://goo.gl/JojsO
브라우저가 캐시를 지우도록 강제 할 수 없습니다.
.html 파일은 10 일 후에 만료되므로 더 빨리 다시로드되는 것 같습니다. 해야 할 일은 .html 파일을 업데이트하고 모든 파일을 같은 새 폴더로 이동 version-2/
하거나 .NET과 같은 각 파일에 버전 식별자를 추가하는 것 mypicture-2.jpg
입니다. 그런 다음 .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" />
그리고 js, css 캐시를 방지하기 위해 도구를 사용하여 매번 임의의 파일 이름을 생성해야하는 스크립트를 축소하고 난독화할 수 있습니다. 그러면 브라우저도 서버에서 다시로드해야합니다.
도움이 되었기를 바랍니다.
"액세스 + 1 초"를 설정하면 다음에 사용자가 사이트에 들어갈 때 새로 고쳐집니다. 설정을 한 달 동안 유지하십시오.
가장 간단한 방법은 요청에 파일 시간을 추가하는 것입니다. 예 :
myfile.txt? 2014-10-30-13 : 12 : 33
날짜 별 버전 관리.
제 경우에는 특정 JS 파일을 많이 변경하고 사용중인 모든 브라우저에서 마지막 버전이어야합니다.
이 파일에 대한 특정 버전 번호가 없으므로 현재 날짜 및 시간 (시간 및 분)을 해시 하고 버전 번호로 전달합니다.
<script src="/js/panel/app.js?v={{ substr(md5(date("Y-m-d_Hi")),10,18) }}"></script>
매분로드해야하지만 언제 다시로드해야하는지 결정할 수 있습니다.
이제 다음은 이미 캐시 된 파일에 대해서는 도움이되지 않지만 앞으로 다음을 사용하여 실제 파일 이름을 변경하지 않고 쉽게 새로운 것을 가져 오도록 요청할 수 있습니다.
# Rewrite all requests for JS and CSS files to files of the same name, without
# any numbers in them. This lets the JS and CSS be force out of cache easily
# by putting a number at the end of the filename
# e.g. a request for static/js/site-52.js will get the file static/js/site.js instead.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^static/(js|css)/([a-z]+)-([0-9]+)\.(js|css)$ /site/$1/$2.$4 [R=302,NC,L]
</IfModule>
물론 폴더 구조에서 이러한 접근 방식을 더 많이 수행할수록 간단한 변경으로 캐시에서 더 많은 것을 제거 할 수 있습니다.
So for example, if you store the entire css and javascript of your site in one main folder
/assets/js
/assets/css
/assets/...
Then you can could start referencing it as "assets-XXX" in your html, and use a rule like so to kick all assets content out of cache.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^assets-([a-z0-9]+)/(.*) /$2 [R=302,NC,L]
</IfModule>
Note that if you do go with this, after you have it working, change the 302 to a 301, and then caching will kick in. When it's a 302 it wont cache at the browser level because it's a temporary redirect. If you do it this way, then you could bump up the expiry default time to 30 days for all assets, since you can easily kick things out of cache by simply changing the folder name in the login page.
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault A2592000
</IfModule>
Change the name of the .CSS file Load the page and then change the file again in the original name it works for me.
This worked for me.
look for this:
DirectoryIndex index.php
replace with this:
DirectoryIndex something.php index.php
Upload and refresh page. You will get a page error.
just change it back to:
DirectoryIndex index.php
reupload and refresh page again.
I checked this on all of my devices and, it worked.
'IT Share you' 카테고리의 다른 글
TeamCity 웹 서버용 포트 변경 (0) | 2020.11.09 |
---|---|
레이블 콘텐츠의 WPF StringFormat (0) | 2020.11.09 |
Xcode에서 줄 번호를 어떻게 찾을 수 있습니까? (0) | 2020.11.09 |
Linq를 사용하여 쉼표로 구분 된 문자열 반환 (0) | 2020.11.09 |
농가 설치 (0) | 2020.11.09 |