问题描述
我正在寻求在PageSpeed上达到100/100,并且我快到了。我正在尝试寻找缓存Google Analytics的好解决方案。
以下是我得到的消息:
利用浏览器缓存
设置到期日期或HTTP头中静态资源的最大使用期限指示浏览器从本地磁盘加载之前下载的资源,而不是通过网络加载。
利用浏览器缓存提供以下缓存资源:
(2小时)
我发现的唯一解决方案是从2012年开始,我不认为这是一个好的解决方案本质上,您可以复制GA代码并自行托管。然后,您运行cron作业,每天重新检查Google一次,以获取最新的GA代码并将其替换。
我还可以做些什么来达到100/100,同时也可以使用Google分析?
谢谢。
欺骗你,你可以骗回Google:
这是pageSpeed的用户代理:
<$ p $ Mozilla / 5.0(X11; Linux x86_64)AppleWebKit / 536.8(KHTML,如Gecko; Google Page Speed Insights)Chrome / 19.0.1084.36 Safari / 536.8
$ c $您可以插入一个条件以避免将分析脚本提供给PageSpeed:
<$ p $
($ _ SERVER ['HTTP_USER_AGENT'])|| stripos($ _ SERVER ['HTTP_USER_AGENT'],'Speed Insights')=== false):?> ;
//此处的分析代码
<?php endif; ?>
显然,它不会有任何真正的改善,但如果您唯一的担心是获得100 / 100分,这将做到这一点。
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:
Leverage browser cachingSetting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.Leverage browser caching for the following cacheable resources:http://www.google-analytics.com/analytics.js (2 hours)
The only solution i've found was from 2012 and I do not think it is a good solution. Essentially you copy the GA code and host it yourself. You then run a cron job to recheck Google once a day to grab the latest GA code and replace it.
http://diywpblog.com/leverage-browser-cache-optimize-google-analytics/
What else can I do to reach 100/100 while also using Google Analytics?
Thank you.
Well, if Google is cheating on you, you can cheat Google back:
This is the user-agent for pageSpeed:
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.8 (KHTML, like Gecko; Google Page Speed Insights) Chrome/19.0.1084.36 Safari/536.8"
You can insert a conditional to avoid serving the analytics script to PageSpeed:
<?php if (!isset($_SERVER['HTTP_USER_AGENT']) || stripos($_SERVER['HTTP_USER_AGENT'], 'Speed Insights') === false): ?>
// your analytics code here
<?php endif; ?>
Obviously, it won't make any real improvement, but if your only concern is getting a 100/100 score this will do it.
这篇关于Google Analytics的PageSpeed Insights 99/100 - 如何缓存GA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!