cod*_*nox 2 browser wordpress .htaccess caching http-headers
我已经尝试获取杠杆浏览器缓存已有一段时间了,但我不知道可能是什么问题。我尝试了几种方法来激活它,但没有任何效果...
该站点在Namecheap主机上运行。我已经联系了支持人员并询问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
Run Code Online (Sandbox Code Playgroud)
我已经尝试过其他一些方法,例如:
## 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 ##
Run Code Online (Sandbox Code Playgroud)
如果有人知道我的代码有什么问题,那将是非常不错的;)
我已经解决了IT 简而言之: -我只是解决了这个问题,但您必须启用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
Run Code Online (Sandbox Code Playgroud)
在深处:
人们看到,他们除了需要利用浏览器缓存外,还做了他们认为的一站式修复,那就是在他们的.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"
Run Code Online (Sandbox Code Playgroud)
看起来一切都很好,但他们然后返回到指标工具,重新进行分析,发现此问题仍然很普遍。然后,他们花了下一个,试图弄清为什么它不起作用并且他们的网站仍在狗屋指标明智。好吧,不是这个问题不是一个网站,可以说是服务器。如果您使用的是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
Run Code Online (Sandbox Code Playgroud)
因此,此列表中没有迹象表明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
Run Code Online (Sandbox Code Playgroud)
回到您的指标并重新运行测试,请确保还将上面指定的代码也添加到htaccess中。您现在应该已经通过了杠杆浏览器缓存测试。
我的网站速度为85,我试图解决杠杆缓存,但最终我用它解决了。截图:-https: //prnt.sc/iu3z2t
归档时间: |
|
查看次数: |
2414 次 |
最近记录: |