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

前端 未结 20 1761
無奈伤痛
無奈伤痛 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:23

    You can set up a cloudfront distribution that has www.google-analytics.com as its origin server and set a longer expiry header in the cloudfront distribution settings. Then modify that domain in the Google snippet. This prevents the load on your own server and the need to keep updating the file in a cron job.

    This is setup & forget. So you may want to add a billing alert to cloudfront in case someone "copies" your snippet and steals your bandwidth ;-)

    Edit: I tried it and it's not that easy, Cloudfront passes through the Cache-Control header with no easy way to remove it

提交回复
热议问题