CentOS 7 の Apache の mod_expires設定ファイルとして、mod_expires.conf作成して、以下のように内容を記載しました。

  • mod_expires.conf
    <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>
    
    設定内容はCentOS 6 で使用していた Apache の設定です。
    これで、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"
    

以上です。

コメント