什么事件迟到了,不影响PagesPeed?

发布于 2025-01-30 04:08:20 字数 950 浏览 3 评论 0原文

(请注意,这不是要制作一个随机工具给我一个更好的数字;我正在诊断出具有可怕性能的着陆页,并且基于Web Vistals评估,真正的用户需要将近10秒钟才能进行互动!!)

我不认为我使用的是JavaScript,但显然我使用的很慢(Google标签管理器和条纹每个添加500-700毫秒之间!!)。

我已经设法获得 https://pagespeed.web.dev/ 到80年代/下90年代对于移动设备,但是我这样做是通过延迟所有JavaScript来完成的。现在,我只加载1个脚本,该脚本在5000ms或第一次用户交互之后加载其他脚本(我检查MOUSTOVERkeydowntouchmove touchmove 或touchstart)。

到目前为止,一切都很好。但是,我想早些时候加载一些脚本(实际上,尽快)。我已经尝试过

window.onload = loadArlyScripts();

document.body.addeventlistener('load',loadArlyScripts);

and

document.body.addEventListener('readystatechange', () => {
  if ( document.readystate === 'complete' ) loadEarlyScripts;
});

,但所有这些都从85中删除了我的PageSpeed performance -95至〜45。因此,用户互动事件足够好,但是这些事件都不是。我可以定位的最早的事件是使PagesPeed开心的最早事件?

(Note, this isn't about making a random tool giving me a better number; I'm diagnosing a landing page that is having terrible performance, and based on the web vitals assessment, real users are taking nearly 10 seconds to get to interactive!)

I don't think I'm using very much JavaScript, but apparently what I am using is quite slow (Google Tag Manager and Stripe each add between 500-700 ms!!).

I've managed to get https://pagespeed.web.dev/ into the upper 80s / lower 90s for mobile, but I've done so by delaying all JavaScript. Now I only load 1 script, and that script loads the other scripts after either 5000ms or first user interaction (I check for mouseover, keydown, touchmove, or touchstart).

So far so good. However, there are some scripts I'd like to load earlier (really, as soon as possible). I've tried

window.onload = loadEarlyScripts();

document.body.addEventListener('load', loadEarlyScripts);

and

document.body.addEventListener('readystatechange', () => {
  if ( document.readystate === 'complete' ) loadEarlyScripts;
});

But all of those drop my PageSpeed performance from 85-95 to ~ 45. So, the user-interaction events are good enough, but none of these are. What's the earliest event I can target that will make PageSpeed happy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文