CDN에 대한 레버리지 브라우저 캐싱을 사용하려는 경우 Cache-Control, Expires 및 Last-Modified와 같은 일부 캐싱 헤더를 추가하여 파일을 캐시하는 것이 좋습니다.
활용 브라우저 캐싱 사용 Mod_Headers
당신이 공유 서버에있어 귀하의 호스트가 mod_expires가 가능하지 않을 경우, 당신은 여전히 사용할 수있는 Mod_headers를 사용하여 브라우저 캐싱을 활용할 수 있습니다. 테스트 예를 들어 아래
# Leverage browser caching using mod_headers #
<IfModule mod_headers.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Wed, 15 Apr 2020 20:00:00 GMT"
Header set Cache-Control "public"
</FilesMatch>
</IfModule>
# End of Leverage browser caching using mod_headers #
:
# 1 YEAR
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 3 HOUR
<FilesMatch "\.(txt|xml|js|css)$">
Header set Cache-Control "max-age=10800"
</FilesMatch>
# NEVER CACHE - notice the extra directives
<FilesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</FilesMatch>
테스트 헤더
당신은 확인할 수 있습니다
캐시-Control : max-age 모두 헤더는 실행 파일에 장소에 "말림"명령은 다음과 같습니다 :
curl -I http://foo.bar.netdna-cdn.com/file.ext
HTTP/1.1 200 OK
Date: Fri, 16 Sep 2014 14:12:20 GMT
Content-Type: text/css
Connection: keep-alive
Cache-Control: max-age=604800, public ← 1 Week caching time
Expires: Thu, 21 May 2015 20:00:00 GMT
Vary: Accept-Encoding
Last-Modified: Thu, 24 Jan 2013 20:00:00 GMT
GMT; path=/; domain=.domain.com
Server: NetDNA-cache/2.2
X-Cache: HIT
당신은 코드 아래 사용하고 있습니다 :
브라우저 캐싱 mod_expires가
브라우저 캐싱을 활용하는 가장 일반적인 방법 mod_expires가를 사용하는 것입니다을 사용. .htaccess에 다음 코드를 추가하면 모든 사용자에 대해 브라우저 캐싱이 자동으로 활성화됩니다.
# Leverage browser caching using mod_expires #
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
# End of Leverage browser caching using mod_expires #
외부 파일입니까? 그렇습니까? 당신은 외부'.JS','css'와 당신이 가지고있는 다른 파일들을 다운로드 받아서 로컬로 실행할 필요가 있습니다. 'cron '을 사용하면됩니다. 이 질문에 대한 내 대답을 확인하십시오. [타사 JS 용 브라우저 캐싱 레버리지] (http://stackoverflow.com/questions/38376871/leverage-browser-caching-for-3rd-party-js/38377857#38377857) – Lag
안녕하세요. @thickguru 파일 다운로드없이 승/달성하는 방법. CDN을 사용하여 성능을 향상시키기위한 목적 때문입니다. 그럴 수 없어 –
당신은 두려워 할 수 없습니다. 외부 파일이 아닙니다. 로컬 파일에서만 작동합니다. 그래서 나는'cron '을 사용할 것을 제안했다. – Lag