Leverage browser caching

纵饮孤独 提交于 2019-12-30 18:59:07

问题


I have a website and when I check page speed with Google plug-in, I receive:

Leverage browser caching The following resources are missing a cache expiration

Where can I change the settings for this?


回答1:


Edit .htaccess and append

<IfModule mod_expires.c>
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 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"
</IfModule>

This link can help you: http://www.quickonlinetips.com/archives/2010/05/leverage-browser-caching-increase-website-speed/




回答2:


Leverage Browser Caching

Reduce the load times of pages by storing commonly used files from your website on your visitors browser.

To enable browser caching you need to edit your HTTP headers to set expiry dates on certain types of files.

Find your .htaccess file in the root of your domain, this file is a hidden file but should show up in FTP clients like FileZilla or CORE. You can edit the htaccess file with notepad or any form of basic text editor.

In this file we will set our caching parameters to tell the browser what types of files to cache.

The code below tells browsers what to cache and how long to "remember" it. It should be added to the top of your .htaccess file.

## EXPIRES CACHING ##
&lt;IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
&lt;IfModule>
## EXPIRES CACHING ##

Recommendations:

  • Be aggressive with your caching for all static resources
  • Expiry at a minimum of one month
  • Don't set your caching more than a year in advance!

Reference: http://websitespeedoptimizations.com/LeverageBrowserCaching.aspx



来源:https://stackoverflow.com/questions/2634172/leverage-browser-caching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!