Set cache expiration?

后端 未结 3 1914
醉梦人生
醉梦人生 2020-12-02 20:43

I tested my site with Chrome and got the following recommendation:

The following resources are missing a cache expiration. Resources that do not specify an e         


        
相关标签:
3条回答
  • 2020-12-02 21:20

    Following the Yahoo! Best Practices for Speeding Up Your Web Site, you should Add an Expires or a Cache-Control Header and Configure ETags.

    How you actually go about configuring the server to do this depends on far more information than you have provided in the question.

    0 讨论(0)
  • 2020-12-02 21:22

    One of the way to Set cache expiration is by using .htaccess file.

    Below code will set expiration for it's respective file type, e.g. for CSS files expiration will be 14 days.

    <IfModule mod_expires.c>
       ExpiresActive on
       ExpiresDefault "access plus 1 month"
       ExpiresByType application/javascript "access plus 1 year"
       ExpiresByType image/x-ico "access plus 1 year"
       ExpiresByType image/jpg "access plus 14 days"
       ExpiresByType image/jpeg "access plus 14 days"
       ExpiresByType image/gif "access plus 14 days"
       ExpiresByType image/png "access plus 14 days"
       ExpiresByType text/css "access plus 14 days"
    </IfModule>
    
    0 讨论(0)
  • 2020-12-02 21:23

    If this question pertains to caching of javascript or css that are a part of your tomcat application directory; you may like to examine the /conf/web.xml file.

    Typically the mime mapping available here is
    <mime-mapping>
       <extension>js</extension>
       <mime-type>application/javascript</mime-type>
    </mime-mapping>

    In apache the default directive is
       ExpiresByType text/javascript "access plus <specify your timeframe>"

    You may like to change the apache directive to application/javascript or change the tomcat mime mapping to text/javascript and this will set the expiration to your timeframe.

    0 讨论(0)
提交回复
热议问题