How do I set expiration on CSS, JS and Images?

前端 未结 5 1426
甜味超标
甜味超标 2021-01-30 07:06

I have recently analysed my website with pagespeed addon on firebug. It suggested me to set expiration on CSS, JS and image files.

I am wondering, how do I do this?

5条回答
  •  甜味超标
    2021-01-30 07:28

    What I do is to create a file "expires.conf" and include it in the site file configuration of Apache. You can include in .htaccess if you want. My expires:

    
        ExpiresActive On
        ExpiresByType image/jpg "access 1 year"
        ExpiresByType image/jpeg "access 1 year"
        ExpiresByType image/gif "access 1 year"
        ExpiresByType image/png "access 1 year"
        ExpiresByType text/css "access 1 month"
        ExpiresByType text/html "access 1 month"
        ExpiresByType application/pdf "access 1 month"
        ExpiresByType text/x-javascript "access 1 month"
        ExpiresByType application/x-shockwave-flash "access 1 month"
        ExpiresByType image/x-icon "access 1 year"
        ExpiresDefault "access 1 month"
    
    

    You need to activate the expires module in apache.

提交回复
热议问题