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, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16154424.html
未经授权禁止转载,违者必究!