简体   繁体   English

Webvitals 主线程阻塞时间

[英]Webvitals Main-Thread Blocking Time

function init() {  
      (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.async = true;
      js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.9&appId=1111";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'))
        
}
window.onload = init;

Despite the fact that I am calling facebook comments plugin on load still i am getting a minus score on web-vitals as its part of Main-Thread Blocking Time .尽管我在加载时调用facebook 评论插件,但作为Main-Thread Blocking Time的一部分,我在 web-vitals 上得到了一个负分。

You should use a Web Worker to load the facebook_comments plugin.您应该使用Web Worker来加载facebook_comments插件。

Web Workers are a simple means for web content to run scripts in background threads. Web Worker 是 web 内容在后台线程中运行脚本的简单方法。

Here's an example:这是一个例子:

facebook_comments.js : facebook_comments.js

function init() {  
      (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.async = true;
      js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.9&appId=1111";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'))    
}

and then load it via the web worker:然后通过 web 工作程序加载它:

new Worker('facebook_comments.js');

That should load the script in a background thread, resulting to an optimized TBT.这应该在后台线程中加载脚本,从而优化 TBT。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 长时间运行的主线程脚本会阻止滚动绘画吗? - Do long-running main-thread scripts block scroll painting? 我可以从库中优化繁重的主线程 JavaScript 视觉效果吗? - Can I optimize a heavy main-thread JavaScript visual effect from a library? Android主线程阻塞WebView线程 - Android main thread blocking WebView thread 如何实现setTimeout()以便它可以跟踪经过的时间而不会阻塞主线程? - How is setTimeout() implemented such that it can keep track of the time elapsed without blocking the main thread? 加载数据表而不阻塞主线程 - Loading a datatable withouth blocking the main thread 有没有办法在不阻塞主线程的情况下异步运行打字稿类方法? - Is there a way to run asynchronously typescript class methods without blocking the main thread? fetch api 是否发生在主线程之外? 如果发生在主线程上,它是如何不被阻塞的? - Does the fetch api happen outside of the main thread? if happening on the main thread how is it not blocking? 如何在不阻塞主线程的情况下处理使用 nodemailer 发送的多封电子邮件 - How to handle multiple emails being sent with nodemailer without blocking main thread 在javascript中阻止UI线程 - Blocking UI thread in javascript 在用户滚动到它们之前触发所有 `content-visibility: auto` 元素的渲染,而不会阻塞主线程超过 50 毫秒 - Trigger rendering of all `content-visibility: auto` elements BEFORE a user scrolls to them without blocking main thread for >50ms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM