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

scheduler API All In One

scheduler API All In One

scheduler API / 专用的调度程序 API

image

https://wicg.github.io/scheduling-apis/#dom-windoworworkerglobalscope-scheduler

Scheduler API: postTask

image

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'});
};

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

https://web.dev/optimize-long-tasks/?utm_source=xgqfrms.xyz#a-dedicated-scheduler-api



©xgqfrms 2012-2021

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

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


posted @ 2023-02-28 14:08  xgqfrms  阅读(50)  评论(0编辑  收藏  举报