靜態元素過時時間

靜態元素過時時間

當用戶訪問網站的時候一些圖片會自動緩存在電腦瀏覽器緩存中,當下一次訪問的時候就沒必要要再次加載了。當超時或更新時,會從新請求加載。javascript

[root@chy logs]# !vim
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.con(配置以下)
 <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType image/gif  "access plus 1 days"
    ExpiresByType image/jpeg "access plus 24 hours"
    ExpiresByType image/png "access plus 24 hours"
    ExpiresByType text/css "now plus 2 hour"
    ExpiresByType application/x-javascript "now plus 2 hours"
    ExpiresByType application/javascript "now plus 2 hours"
    ExpiresByType application/x-shockwave-flash "now plus 2 hours"
    ExpiresDefault "now plus 0 min"
</IfModule>
以上爲增長的內容,以下爲配置的詳解
<IfModule mod_expires.c>
    ExpiresActive on  //打開該功能的開關
    ExpiresByType image/gif  "access plus 1 days" (定義gif的失效時間)
    ExpiresByType image/jpeg "access plus 24 hours"(定義jpeg的失效時間)
    ExpiresByType image/png "access plus 24 hours"
    ExpiresByType text/css "now plus 2 hour"
    ExpiresByType application/x-javascript "now plus 2 hours"
    ExpiresByType application/javascript "now plus 2 hours"
    ExpiresByType application/x-shockwave-flash "now plus 2 hours"
    ExpiresDefault "now plus 0 min"
</IfModule>

測試並查看增長模塊css

[root@chy ~]# /usr/local/apache2.4/bin/apachectl -M |grep expire
(模塊並麼有打開)
[root@chy ~]# vim /usr/local/apache2.4/conf/httpd.conf
(編輯主配置文件)
#LoadModule expires_module modules/mod_expires.so
(找到expires並把它的註釋去掉:LoadModule expires_module modules/mod_expires.so
)
[root@chy ~]# /usr/local/apache2.4/bin/apachectl graceful
(加載一下配置文件)
[root@chy ~]# /usr/local/apache2.4/bin/apachectl -M |grep expire
 expires_module (shared)
(而後查看此模塊是否存在)
測試:
[root@chy 111.com]# curl -x127.0.0.1:80 www.111.com/lf.png -I
HTTP/1.1 200 OK
Date: Thu, 03 Aug 2017 00:00:31 GMT
Server: Apache/2.4.27 (Unix) PHP/5.6.30
Last-Modified: Wed, 19 Oct 2016 08:52:35 GMT
ETag: "1bca7-53f33ee277ac0"
Accept-Ranges: bytes
Content-Length: 113831
Cache-Control: max-age=86400
Expires: Fri, 04 Aug 2017 00:00:31 GMT
Content-Type: image/png
相關文章
相關標籤/搜索