根据:http ://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching我应该使用浏览器缓存。但是,我不知道怎么做。
我是否只是将某些标签添加到 html 部分?还是我需要通过服务器发送给客户端的东西?与php标头有关吗?
缓存是通过各种 HTTP 标头控制的。您应该阅读 Mark Nottingham 的Web Authors and Webmasters 缓存教程。您可以使用header函数为 PHP 输出的文档设置 HTTP 标头。
您可以在 .htaccess 中执行类似的操作。
## EXPIRES CACHING ##
<IfModule mod_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 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 2 days"
</IfModule>
## EXPIRES CACHING ##