I\'m on a quest to reach 100/100 on PageSpeed and i\'m almost there. I\'m trying to find a good solution to cache Google Analytics.
Here is the message I get:
To fix this issue you would have to download the file locally and run a cron job to keep updating. Note: this doesn't make your website any faster at all so its best to just ignore it.
For demonstration purposes however, follow this guide: http://diywpblog.com/leverage-browser-cache-optimize-google-analytics/
Open https://www.google-analytics.com/analytics.js file in a new tab, copy all the code.
Now create a folder in your web directory, rename it to google-analytics.
Create a text file in the same folder and paste all the code you copied above.
Rename the file ga-local.js
Now change the URL to call your locally hosted Analytics Script file in your Google Analytics Code. It will look something like this i.e. https://domain.xyz/google-analytics/ga.js
Finally, place your NEW google analytics code into the footer of your webpage.
You are good to go. Now check your website of Google PageSpeed Insights. It will not show the warning for Leverage Browser Caching Google Analytics. And the only problem with this solution is, to regularly update the Analytics Script manually.