将此粘贴到。HTACCESS文件:
Header unset ETag
FileETag None
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 35 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
这将告诉浏览器将所有javascript、图像、css缓存到计算机,所以图像在更改之前不会从您处下载。您可以使用最佳浏览器-chrome在时间线中使用ctrl+shift+j进行测试您可以实际看到下载图像所需的时间,缓存的图像通常需要25 ms(因为服务器首先必须说明:文件未更改,所以请使用本地副本:))