mod_expires

最後更新: 2016-10-14

介紹

 

它是一個設定 responses header 的 module 來, 它會設定

  • "Expires: ..."HTTP header
  • "Cache-Control: max-age=xxx"  HTTP header
    (max-age directive of the Cache-Control)

 * 有時用 "Header set Cache-Control "max-age=600, public"" 可能會簡單一點

 


ExpiresByType 設定

 

Enables or Disables

ExpiresActive On|Off

設定過期時間

ExpiresDefault  "base [[plus] num type] [num type] ..."

ExpiresByType  type/encoding  "base [[plus] num] [num type]"

base:

  • access
  • modification

time unit:

  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds

Example:

.htaccess

<IfModule mod_expires.c>
   ExpiresActive On
   # txt
   ExpiresByType application/x-javascript "access plus 30 minutes"
   ExpiresByType text/css "access plus 30 minutes"
   # 圖
   ExpiresByType image/png "access plus 30 minutes"
   ExpiresByType image/gif "access plus 30 minutes"
   ExpiresByType image/jpg "access plus 30 minutes"
   ExpiresByType image/jpeg "access plus 30 minutes"
   # 片
   ExpiresByType application/x-shockwave-flash "access plus 30 minutes"
   ExpiresByType video/mp4 "access plus 30 minutes"
   ExpiresByType video/avi "access plus 30 minutes"
</IfModule>

OR

# image file
<FilesMatch "\.(jpe?g|png|bmp|gif)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 week"
</FilesMatch>

P.S.

/etc/mime.types

 


ExpiresDefault 設定

 

# It can be overridden on a type-by-type basis by the ExpiresByType directive.

i.e.

ExpiresDefault "access plus 30 minutes"

 


Client Side View

 

# 留意 Cache-Control 及 Expires

 

 

附加檔案大小
http_header.png10.94 KB

Creative Commons license icon Creative Commons license icon