gpt4 book ai didi

wordpress - 利用浏览器缓存不起作用 - Htaccess 和 mod_expires Active

转载 作者:行者123 更新时间:2023-12-02 11:28:05 26 4
gpt4 key购买 nike

我已经尝试利用浏览器缓存很长一段时间了,但我不知道可能是什么问题。我尝试了多种方法来激活它,但没有任何效果......

该网站正在 Namecheap Hosting 上运行。我已经联系了支持人员并询问 mod_expires 模块是否处于事件状态,根据客户支持,它是...

这是我一直在使用的代码:

# START --- Browser Cache Control
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>

# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"
</FilesMatch>

# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
# END --- Browser Cache Control

我已经尝试过其他一些方法,例如:

## EXPIRES CACHING ##
<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 text/html "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 1 month"
</IfModule>
## EXPIRES CACHING ##

如果有人知道我的代码可能有什么问题,那就太好了;)

最佳答案

我已经解决了简而言之:-我刚刚解决了这个问题,但你必须启用 expires_module 模块。对于Linux,你可以像这样简单地做到这一点。

azureuser@azure: sudo a2enmod expires
Enabling module expires.
To activate the new configuration, you need to run:
service apache2 restart
azureuser@azure: sudo service apache2 restart
[....] Restarting web server:
. ok

深入:-

人们发现他们需要利用浏览器缓存,因此他们做了他们认为的一站式修复,即在他们的 .htaccess 文件中添加如下内容:

ExpiresActive On
ExpiresDefault "access plus 5 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"

这看起来一切都很好,但他们然后回到他们的指标工具,重新分析并发现这个问题仍然普遍存在。然后他们花了接下来的时间试图找出为什么这不起作用以及他们的网站仍然是在狗屋指标方面。不用担心,问题不是网站问题,而是服务器问题。如果您使用的是 Debian 服务器,这就是您一直在寻找的快速修复:登录您的 Dedicated/VPS 并发出以下命令,该命令将检查您的服务器上加载了哪些模块,您正在寻找 expires_module列表

azureuser@azure: sudo apachectl -M
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
mime_module (shared)
negotiation_module (shared)
php5_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
ssl_module (shared)
status_module (shared)
Syntax OK

所以这个列表中没有expires_module的迹象,接下来你要做的就是安装它

azureuser@azure: sudo a2enmod expires
Enabling module expires.
To activate the new configuration, you need to run:
service apache2 restart
azureuser@azure: sudo service apache2 restart
[....] Restarting web server:
. ok

返回您的指标并重新运行测试,请务必将上面指定的代码也添加到您的 htaccess 中。您现在应该已经通过了 Leverage 浏览器缓存测试。

我的网站速度是 85,我试图解决杠杆缓存问题,但最终我用这个解决了它。截图:-https://prnt.sc/iu3z2t

关于wordpress - 利用浏览器缓存不起作用 - Htaccess 和 mod_expires Active,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465684/

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