16

我安装了Yslow插件

替代文字

当我在 Yslow 中检查我的应用程序时,我得到了我不知道的Add Expires 标头

替代文字

我在 SO 和 Google 中搜索了相关问题,我发现这种方法很合适

<?
    header("Expires:".gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    ob_start();
    session_cache_limiter('public');
    session_start();
?>
<html>

但它仍然显示我相同

因为我是新手,所以我对 .htaccess 了解不多

请帮助我提高应用程序性能

提前致谢

时髦的

4

1 回答 1

14

这只会为您的页面内容设置它,而不是图像和 css 文件之类的东西,我注意到在您的屏幕截图上它显示 42 个文件,大概这些是您的图像、css、js 等。

在您的 .htaccess 文件中尝试此操作,请注意,这仅在您已在 Apache 中启用mod_expires并启用时才有效:mod_headers

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"  
</ifModule>

<ifModule mod_headers.c>
  <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
  <filesMatch "\\.(xml|txt)$">
    Header set Cache-Control "max-age=216000, public, must-revalidate"
  </filesMatch>
  <filesMatch "\\.(html|htm|php)$">
    Header set Cache-Control "max-age=1, private, must-revalidate"
  </filesMatch>
</ifModule>
于 2011-01-05T10:43:33.583 回答