PageSpeed Insights 99/100 because of Google Analytics - How can I cache GA?

前端 未结 20 1530
無奈伤痛
無奈伤痛 2020-11-29 15:10

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:

相关标签:
20条回答
  • 2020-11-29 15:44

    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/

    0 讨论(0)
  • 2020-11-29 15:44

    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.

    0 讨论(0)
提交回复
热议问题