大网数据广告活动
Web 标准与前端开发

Worklet

· 52CE 我爱测

The **`Worklet`** interface is a lightweight version of Web Workers and gives developers access to low-level parts of the rendering pipeline.

Worklets

The Worklet interface is a lightweight version of Web Workers and gives developers access to low-level parts of the rendering pipeline.

With Worklets, you can run JavaScript and WebAssembly code to do graphics rendering or audio processing where high performance is required.

Worklets allow static import of ECMAScript modules, if supported, using import. Dynamic import is disallowed by the specification — calling import() will throw.

Worklet types

Worklets are restricted to specific use cases; they cannot be used for arbitrary computations like Web Workers. The Worklet interface abstracts properties and methods common to all kind of worklets, and cannot be created directly. Instead, you can use one of the following classes:

<table class="no-markdown"> <thead> <tr> <th>Name</th> <th>Description</th> <th>Location</th> <th>Specification</th> </tr> </thead> <tbody> <tr> <td>AudioWorklet</td> <td>For audio processing with custom AudioNodes.</td> <td>Web Audio render thread</td> <td> <a href="https://webaudio.github.io/web-audio-api/#AudioWorklet" >Web Audio API</a > </td> </tr> <tr> <td>AnimationWorklet</td> <td> For creating scroll-linked and other high performance procedural animations. </td> <td>Compositor thread</td> <td> <a href="https://wicg.github.io/animation-worklet/" >CSS Animation Worklet API</a > </td> </tr> <tr> <td>LayoutWorklet</td> <td>For defining the positioning and dimensions of custom elements.</td> <td></td> <td> <a href="https://drafts.css-houdini.org/css-layout-api-1/#layout-worklet" >CSS Layout API</a > </td> </tr> <tr> <td>SharedStorageWorklet</td> <td>For running private operations on cross-site data, without risk of data leakage.</td> <td>Main thread</td> <td> <a href="https://wicg.github.io/shared-storage/" >Shared Storage API</a > </td> </tr> </tbody> </table>

[!NOTE] Paint worklets, defined by the CSS Painting API, don't subclass Worklet. They are accessed through a regular Worklet object obtained using CSS.paintWorklet_static.

For 3D rendering with WebGL, you don't use worklets. Instead, you write vertex shaders and fragment shaders using GLSL code, and those shaders will then run on the graphics card.

Instance properties

The Worklet interface does not define any properties.

Instance methods

  • Worklet.addModule()
    • : Adds the script module at the given URL to the current worklet.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。