AddThis和Google Page Speed

Str*_*ped 5 javascript asp.net jquery micro-optimization addthis

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

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

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

我尝试使用延迟(对于IE)和异步(对于FF和Chrome)将脚本标记添加到我的页面的头部而没有运气:

<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=myUserId" defer="defer" async="async"></script>
Run Code Online (Sandbox Code Playgroud)

我尝试过使用$ .getScript():

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

我也试过打开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 });
    });
});
Run Code Online (Sandbox Code Playgroud)

有什么方法可以缓存,还推迟加载AddThis和它的外部引用?

Ari*_*tos 0

利用浏览器缓存

嗯,这只是一个建议,为某些页面设置更多的时间缓存。在我的页面上,我收到这两个警告 - 均来自谷歌脚本:)。并不是那么重要,因为这个 javascript 已经准备好了,有一个很好的 javascript 时间缓存。

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

推迟 Javascript 的解析

嗯,这是一个自动程序,尝试了解页面是否缓慢并提出一些改进建议。在这一点上是不准确的。

我只是在已知页面上运行它,该页面可以找到并充满缓存和其他技巧,并获得相同的消息。

就像只是一个建议,实际上并不知道这个 javascript 是否真的做好了他所说的一切 - 至少目前是这样。例如,在我的测试页面中,我在页面末尾加载了 JavaScript,然后再次收到此消息。如果您知道您在正确的时间使用正确的标志加载了 javascript,则不必担心此消息。

检查此页面的报告:

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