I´ve been trying to get The leverage browser cache for quite a while and I have no idea what could be the problem. I tried several methods to activate it, but nothing works...
The site is running on Namecheap Hosting. I already contacted the support and asked if the mod_expires module is active and according to the customer support it is...
This is the code I´ve been using:
# 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
I already tried some other methods like:
## 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 ##
It would be really nice if anyone has an idea what could be wrong with my code ;)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With