scheduler API All In One
scheduler API / 专用的调度程序 API
https://wicg.github.io/scheduling-apis/#dom-windoworworkerglobalscope-scheduler
Scheduler API: postTask
https://wicg.github.io/scheduling-apis/#dom-scheduler-posttask
dom.enable_web_task_scheduling: true
Web 性能优化
https://caniuse.com/?search=scheduler API
https://developer.mozilla.org/en-US/docs/Web/API/Window/scheduler
Prioritized Task Scheduling API / 优先任务调度 API
The Prioritized Task Scheduling API provides a standardized way to prioritize all tasks belonging to an application, whether they defined in a website developer's code, or in third party libraries and frameworks.
Prioritized Task Scheduling API 提供了一种标准化方法
来确定属于应用程序的所有任务
的优先级
,无论它们是在网站开发人员的代码中定义的,还是在第三方库
和框架
中定义的。
Feature checking / 特征检查
// Check that feature is supported
if ('scheduler' in this) {
mylog('Feature: Supported ✅);
} else {
mylog('Feature: NOT Supported ❌;
}
https://developer.mozilla.org/en-US/docs/Web/API/Prioritized_Task_Scheduling_API
heduler.postTask
const promise = scheduler.postTask(myTask);
// A function that defines a task
function myTask() {
return 'Task 1: user-visible';
}
if ('scheduler' in this) {
// Post task with default priority: 'user-visible' (no other options)
// When the task resolves, Promise.then() logs the result.
scheduler.postTask(myTask).then((taskResult) => mylog(`${taskResult}`));
}
https://developer.mozilla.org/en-US/docs/Web/API/Scheduler/postTask
demos
function saveSettings () {
// Validate the form at high priority
scheduler.postTask(validateForm, {priority: 'user-blocking'});
// Show the spinner at high priority:
scheduler.postTask(showSpinner, {priority: 'user-blocking'});
// Update the database in the background:
scheduler.postTask(saveToDatabase, {priority: 'background'});
// Update the user interface at high priority:
scheduler.postTask(updateUI, {priority: 'user-blocking'});
// Send analytics data in the background:
scheduler.postTask(sendAnalytics, {priority: 'background'});
};