When I run Google PageSpeed Insights I get the following optimization suggestion.
When I click the Leverage browser caching link it sends me to a page that recommends I use Cache-Control or ETags.
Setting up Cache-Control
with .htaccess
should be simple enough so I included the following lines inside of my existing .htaccess
file.
<IfModule mod_headers.c>
<filesMatch "https://www.google-analytics.com/analytics.js">
Header set Cache-Control "max-age=7200, public"
</filesMatch>
<filesMatch "https://www.googletagmanager.com/gtag/js?id=UA-00000000-0">
Header set Cache-Control "max-age=900, public"
</filesMatch>
</IfModule>
I uploaded the .htaccess
file, tested it and got the same error. Even though Google recommends using Cache-Control
that doesn't solve the problem.
When that didn't work I tried ExpiresByType
but it didn't solve them problem either.
<IfModule mod_expires.c>
ExpiresActive On
<IfModule mod_expires.c>
ExpiresByType application/javascript "access plus 2 hours"
</IfModule>
</IfModule>
Is there a way to use an .htaccess
file to instruct browsers to cache these files or is that not possible?