xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Background Tasks API All In One

Background Tasks API All In One

性能优化

Cooperative Scheduling of Background Tasks API

后台任务协同调度 API

requestIdleCallback


window.requestIdleCallback = window.requestIdleCallback || function(handler) {
  let startTime = Date.now();
  return setTimeout(function() {
    handler({
      didTimeout: false,
      timeRemaining: function() {
        return Math.max(0, 50.0 - (Date.now() - startTime));
      }
    });
  },  0);
}

cancelIdleCallback


Web API

https://developer.mozilla.org/en-US/docs/Web/API/Background_Tasks_API

https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback

https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelIdleCallback

demo

if (typeof globalThis.window.requestIdleCallback === 'function') {
  requestIdleCallback(() => {
    new Fingerprint().get(function (result, components) {
      console.log(result);
      console.log(components);
    });
  }, {
    timeout: 0,
  });
} else {
  setTimeout(function () {
    new Fingerprint().get(function (result, components) {
      console.log('result =', result);
      console.log('components =', components);
    });
  }, 0);
}

refs

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-04-16 22:03  xgqfrms  阅读(56)  评论(2编辑  收藏  举报