Leverage browser caching not working - Htaccess & mod_expires Active

假如想象 提交于 2019-12-06 13:46:12

I HAVE RESOLVED IT In short:- I just resolved this issue but you have to enable expires_module module. For linux you can do it easy like that.

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

In Deep:-

People are seeing that among other things they need to Leverage Browser Caching, so they do what they think is the one stop fix and thats to add something like the following to their .htaccess file:

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"

This seems all well and good but they then go back to their metrics tool, re-analyse and see that this issue is still prevalent.. They then spend the next while trying to figure out why this is not working and their website is still in the dog house metrics wise. well fear not the issue is not a website one so to speak, its a server one. If you are using a Debian server this is the quick fix you have been looking for: log into your Dedicated/VPS and issue the following command which will check to see what modules are loaded on your server, you are looking for the expires_module in the list

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

So there is no sign of the expires_module in this list, next up all you have to do is install it

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

Head back to your metrics and rerun the test, be sure to add the code specified above to your htaccess also. You should now have passed the Leverage browser Caching test.

My website speed was 85, I was trying to resolve Leverage cache but finally i resolved it with this. Screenshot:- https://prnt.sc/iu3z2t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!