gpt4 book ai didi

.htaccess - htaccess缓存不起作用

转载 作者:行者123 更新时间:2023-12-04 01:40:22 24 4
gpt4 key购买 nike

我将以下内容输入到我的“.htacces”文件中以开始缓存 Web 内容。根据 Google Page Speed 和 Yslow,页面仍未缓存。模块错了吗?还是应用程序没有正确显示数据?

站点在服务器上的 Apache 2.0 上运行

.htaccess(包含缓存模块):

# Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 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>
 
# Cache-Control Headers
<ifModule mod_headers.c>
#month
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
#week
  <filesMatch "\.(css|js)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
#day
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=43200, private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers
 
# Turn ETags Off
<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
FileETag None
 
# Remove Last-Modified Header
<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>

最佳答案

进入httpd.conf并寻找 mod_expires行,它不应该被注释掉。寻找 mod_headers行并确保它没有被注释掉。

或者(不适用于关键应用程序)有一个简单而肮脏的测试:删除 <ifModule mod_expires.c></ifModule>把东西放在中间,<ifModule mod_headers.c> 也是如此如果您的服务器因 500 互联网服务器错误而失败,那么您可能缺少这些模块中的一个或两个,并且它们未启用。如果是这样,请进入 httpd.conf 并启用您需要的内容。

您还可以使用 REDbot 之类的工具测试站点的响应 header 。 .只需选择一个资源 URL,例如指向图像的 URL,然后将其粘贴到工具中,即可查看返回的 header 以及一些建议。请注意,它遵循域的 robots.txt 规则,如果不允许,则不会检查资源。

就像 Gerben 所说,使用 Firefox、chrome 开发工具或一些等效的 Web 开发工具中的 net 选项卡有助于查看正在发送和接收的 header 。

您也不需要设置Cache-Control public .而且你不需要使用max age如果您还使用 ExpiresByType来电。

欲了解更多信息,请阅读这篇精彩的教程:http://www.mnot.net/cache_docs/

并通过示例学习:在 html5-boilerplate 中查看它是如何完成的在 https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

对于其他流行的服务器配置示例,如 lighthttpd , Node.js , Nginx等见:
https://github.com/h5bp/server-configs

关于.htaccess - htaccess缓存不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8513791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com