Worklet - Web APIs 编辑

Experimental

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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.

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:

NameDescriptionLocationSpecification
PaintWorklet

For programmatically generating an image where a CSS property expects a file. Access this interface through CSS.paintWorklet.

Chrome: Main thread
Gecko: Paint thread
CSS Painting API
AudioWorkletFor audio processing with custom AudioNodes.Web Audio render threadWeb Audio API
AnimationWorkletFor creating scroll-linked and other high performance procedural animations.Compositor threadCSS Animation Worklet API
LayoutWorkletFor defining the positioning and dimensions of custom elements.CSS Layout API

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.

Properties

The Worklet interface does not define any properties.

Methods

Worklet.addModule() This is an experimental API that should not be used in production code.
Adds the script module at the given URL to the current worklet.

Specifications

Specification
HTML Living Standard
The definition of 'Worklet' in that specification.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:67 次

字数:5361

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文