我一直在测试是什么导致我的灯塔分数低,似乎当我删除以下脚本时,它上升了30%!我也不知道为什么。
这是脚本(smartupp -一个网络聊天帮助应用程序)
<script
defer
type="text/javascript"
dangerouslySetInnerHTML={{ __html: `
var _smartsupp = _smartsupp || {};
_smartsupp.key = 'key';
window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
` }}
/>
我在我的页面末尾加入了这一点。当我将其包括在内时,在灯塔得分中显示为"Reduce unused JavaScript“,我认为这是因为smartupp包括以下内容:
有没有人知道为什么这个脚本会让我的表现变得如此缓慢?以及我能做些什么来改善它。
我使用的是NextJs (React)。
发布于 2021-04-28 21:19:16
在页面加载时加载整个聊天应用程序。但您可能只会在用户单击某个按钮时使用它。
我的建议是添加一个具有相同设计的按钮,并仅在用户单击它后加载此smartsuppchat脚本。在加载后打开聊天需要一些额外的逻辑,但您需要参考有关这一点的smartsuppchat文档。
https://stackoverflow.com/questions/67307628
复制