I have developed a web page and I have tested it in different tools to check its performance and speed. Overall, the results are good, but there is one section that everyone gives me a lower grade on: " leverage browser caching ".
Looking on the Internet, I found that I can indicate how long I want some elements to be stored in the cache by modifying the file .htaccess
, to which I added the following:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/svg "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
With this I try to make the cache last one year for images and icons, and 2 days by default for the rest of the content. I run the tests again and it gives me a bad grade again for the " leverage browser caching " section.
What am I doing wrong? How can I take better advantage of the browser cache?
The causes could be different, depending on the tool you are using to check this.
Some that come to mind:
As I mentioned, the tool may be basing its score on one of the guidelines that I indicate. Many times the tools then refer to the items that are failing, check that option to confirm what the problem may be. Most likely, the ExpiresDefault is set too low.
Cheers,