W3cubDocs

/Web APIs

Worklet

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:

Name Description Location Specification
AudioWorklet For audio processing with custom AudioNodes. Web Audio render thread Web Audio API
AnimationWorklet For creating scroll-linked and other high performance procedural animations. Compositor thread CSS Animation Worklet API
LayoutWorklet For defining the positioning and dimensions of custom elements. CSS Layout API

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.

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

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Worklet 65 79 76 No 52 14.1 65 65 79 47 14.5 9.0
addModule 65 79 76 No 52 14.1 65 65 79 47 14.5 9.0
ecmascript_modules 80 80 114 No 67
15["Nested workers support was introduced in Safari 15.5.", "Script loading in nested workers was introduced in Safari 16.4."]
80 80 114 57
15["Nested workers support was introduced in Safari 15.5.", "Script loading in nested workers was introduced in Safari 16.4."]
13.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Worklet