首页 > 编程语言 > 详细

[Javascript] Use requestIdleCallback to schedule JavaScript tasks at an optimal time

时间:2019-11-13 21:14:01      阅读:87      评论:0      收藏:0      [点我收藏+]

JavaScript is single-threaded, which can present some problems when creating an interactive user experience. If JavaScript runs too long while a user is attempting to interact with a page, it can cause noticeable jank or lag, which degrades the experience. requestIdleCallback is a DOM API that allows you to schedule a JavaScript function to be run when the page thread is idle, so your JavaScript doesn‘t get in the way of the user.

 

let id = requestIdleCallback(
  () => {
    console.log("idle callback called");
  },
  { timeout: 2000 } // the function must be run within 2 seconds
);

cancelIdleCallback(id);

 

[Javascript] Use requestIdleCallback to schedule JavaScript tasks at an optimal time

原文:https://www.cnblogs.com/Answer1215/p/11853163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!