5

No matter how I try to load AddThis (using Google +1, Facebook Send and Like, and Twitter buttons as default), Google Page Speed still warns about:

  • Leverage browser caching
  • Defer parsing of Javascript

In each of these items, .html and .js references to AddThis, Facebook, Google +1, Twitter, and static.ak.fbcdn.net are referenced. In fact, if you run Google Page Speed on this page: http://support.addthis.com/customer/portal/articles/381263-addthis-client-api-#rendering-js, you will see exactly what I'm talking about. The first two items, both with orange severity icons (at least for me), are exactly what I mentioned above.

I've tried adding the script tag to the head of my page using defer (for IE) and async (for FF and Chrome) with no luck:

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

I've tried using $.getScript():

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

And I also tried turning the ajax cache on:

$(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 });
    });
});

Is there any way I can cache, and also defer the loading of AddThis and it's external references?

4

2 に答える 2

0

ブラウザのキャッシュを利用する

これは、一部のページのタイムキャッシュを増やすための提案にすぎません。私のページでは、この2つの警告が表示されます-両方ともgooglescriptから:)。このjavascriptはすべて準備ができているので、javascript用の適切な時間キャッシュがあるため、それほど重要ではありません。

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

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

于 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 に答える