5

无论我如何尝试加载 AddThis(默认使用 Google +1、Facebook Send 和 Like 和 Twitter 按钮),Google Page Speed仍然会发出以下警告:

  • 利用浏览器缓存
  • 延迟 Javascript 的解析

在这些项目中的每一项中,都引用了对 AddThis、Facebook、Google +1、Twitter 和 static.ak.fbcdn.net 的 .html 和 .js 引用。事实上,如果你在这个页面上运行 Google Page Speed:http: //support.addthis.com/customer/portal/articles/381263-addthis-client-api-#rendering-js,你会看到我到底是什么谈论。前两项都带有橙色严重性图标(至少对我而言),正是我上面提到的。

我尝试使用 defer(对于 IE)和 async(对于 FF 和 Chrome)将脚本标签添加到我的页面头部,但没有成功:

<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=myUserId" defer="defer" async="async"></script>

我试过使用 $.getScript():

$(document).ready(function () {
    $.getScript('http://s7.addthis.com/js/250/addthis_widget.js#async=1#username=myUserId', function(data, textStatus) {
        addthis.init();
    });
});

我还尝试打开 ajax 缓存:

$(document).ready(function () {
    $.ajaxSetup({ cache: true });
    $.getScript('http://s7.addthis.com/js/250/addthis_widget.js#async=1#username=myUserId', function(data, textStatus) {
        addthis.init();
        $.ajaxSetup({ cache: false });
    });
});

有什么办法可以缓存,也可以推迟加载 AddThis 及其外部引用?

4

2 回答 2

0

Leverage browser caching

Well this is just a proposal to set more time cache of some pages. On my pages I get this two warning - both from google script :). Is not so important because this javascript all ready have a good time cache for javascript.

http://pagead2.googlesyndication.com/pagead/show_ads.js (60 minutes)
http://www.google-analytics.com/ga.js (2 hours)

Defer parsing of Javascript

Well, this is an automatic program that try to understand if the page is slow and suggest some thinks to improve it. At this point is not accurate.

I just run it on known page that work find and full of cache and other tricks, and get the same messages.

Is like just a suggestion and not actually can know if this javascript really do all ready what he say - at least for the moment. For example in my test page I load a javascript at the end of the page and I get this message again. If you know that you load the javascript at the correct timing with the correct flags, do not worry about this messaage.

Check the report for this page :

https://developers.google.com/pagespeed/#url=http_3A_2F_2Fstackoverflow.com_2Fquestions_2F9739031_2Faddthis-and-google-page-speed&mobile=false&rule=LeverageBrowserCaching

于 2012-03-16T14:31:20.517 回答
0
<script type="text/javascript"charset="utf-8" src="/js/addthis.js#async=1"</script>

这已在我们的网站中解决。http://www.nbhuntop.com 您可以先尝试复制 addthis 代码。并引用为src="/js/addthis.js#async=1"

于 2012-04-29T03:18:14.577 回答