CentOS 7 の Apache の mod_expires
の設定ファイルとして、mod_expires.conf
を作成して、以下のように内容を記載しました。
- mod_expires.conf
設定内容はCentOS 6 で使用していた Apache の設定です。<IfModule expires_module> ExpiresActive On # static content ExpiresByType image/jpeg "access plus 1 months" ExpiresByType image/gif "access plus 1 months" ExpiresByType image/png "access plus 1 months" ExpiresByType text/css "access plus 1 months" ExpiresByType text/javascript "access plus 1 months" # Font ExpiresByType application/vnd.ms-fontobject "access plus 1 year" ExpiresByType application/x-font-ttf "access plus 1 year" ExpiresByType application/x-font-opentype "access plus 1 year" ExpiresByType application/x-font-woff "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType application/font-woff2 "access plus 1 year" ExpiresByType application/font-woff "access plus 1 year" ExpiresByType image/x-icon "access plus 1 year" ExpiresByType image/vnd.microsoft.icon "access plus 1 year" </IfModule>
これで、javascript の Cache 有効期限は 1月になると思っていましたが、有効期限が設定されませんでした。
CentOS 6 と CentOS 7 では、JavaScript の Mime Type の設定が異なるようで、/etc/mime.types
には以下のように記載されていました。
** CentOS 7**
application/javascript js
** CentOS 6**
text/javascript js
JSの MIME-Type は text か application か、x- は必要か – カラクリ.jp の説明を見る限り、application/javascript
が推奨される MIME Type のようです。
sonarwhal/sonarwhal: A linting tool for the web で ‘content-type’ header should have media type ‘text/javascript’ (not ‘application/javascript’)
という警告が出るので、text/javascript
が推奨かなとか思っていたのですが、違うようです。1
mod_expires.conf
に、以下記述を追加しました。
- 追加した記述
ExpiresByType application/javascript "access plus 1 months"
以上です。
-
content-type と、MIME Type は似て非なるものなんですね。「MIMEタイプ」と「Content-type」の違い|「分かりそう」で「分からない」でも「分かった」気になれるIT用語辞典 ↩
コメント