javascript - How to best defer scripts to be excluded from PageSpeed Insights? - Stack Overflow

We use Zopim on our website. Unfortunately, because of this we are significantly punished on PageSpeed

We use Zopim on our website. Unfortunately, because of this we are significantly punished on PageSpeed Insights.

  • Without Zopim: 86/100
  • With Zopim: 66/100

Zopim seems to be aware of the issue, and promises to further optimize their widget, but we haven't seen much progress yet.

The code to add Zopim is as follows:

<script type="text/javascript">
  window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
  d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
  _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute("charset","utf-8");
  $.src="/?2dAdkKRoqdi9hHHrfr302XabQaK8DN7f";z.t=+new Date;$.
  type="text/javascript";e.parentNode.insertBefore($,e)})(document,"script");
</script>

I have been playing around with different ways of deferring the execution of the script (defer and async), but have been unsuccessful in improving our PageSpeed Insights score (without removing Zopim altogether).

I came to this article but my naive attempt (replace "defer.js" with "/?2dAdkKRoqdi9hHHrfr302XabQaK8DN7f") did not have the desired effect and Zopim is still counted by PageSpeed.

My question:

  • what is the best way to defer non-critical scripts to ensure that PageSpeed Insights do not count the script as part of its score?
  • how to apply that to the Zopim script?

We use Zopim on our website. Unfortunately, because of this we are significantly punished on PageSpeed Insights.

  • Without Zopim: 86/100
  • With Zopim: 66/100

Zopim seems to be aware of the issue, and promises to further optimize their widget, but we haven't seen much progress yet.

The code to add Zopim is as follows:

<script type="text/javascript">
  window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
  d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
  _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute("charset","utf-8");
  $.src="https://v2.zopim./?2dAdkKRoqdi9hHHrfr302XabQaK8DN7f";z.t=+new Date;$.
  type="text/javascript";e.parentNode.insertBefore($,e)})(document,"script");
</script>

I have been playing around with different ways of deferring the execution of the script (defer and async), but have been unsuccessful in improving our PageSpeed Insights score (without removing Zopim altogether).

I came to this article but my naive attempt (replace "defer.js" with "https://v2.zopim./?2dAdkKRoqdi9hHHrfr302XabQaK8DN7f") did not have the desired effect and Zopim is still counted by PageSpeed.

My question:

  • what is the best way to defer non-critical scripts to ensure that PageSpeed Insights do not count the script as part of its score?
  • how to apply that to the Zopim script?
Share Improve this question edited Jan 13, 2019 at 6:48 chrisvdb asked Jan 13, 2019 at 6:32 chrisvdbchrisvdb 2,2003 gold badges22 silver badges30 bronze badges 2
  • 1 In the end we deferred Zopim by 4 seconds, which is sufficient for Google PageSpeed Insights to ignore it altogether in its score. – chrisvdb Commented Jan 16, 2019 at 3:52
  • I'm dealing with this too

    发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744114357a4559100.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信