Skip to content

Browser Helpers

Utility functions for working with browser operations.

FunctionDescription
decodeImageLoads an image and waits until it is decoded, so it can be painted without a flash or a decoding pause (e.g.
loadFontLoads a font and registers it in `document.fonts`, so CSS and canvas can use `family` right away.
matchesMediaWhether the document currently matches a CSS media query.
observeIntersectionCalls `callback` each time `element` enters or leaves the viewport (or `options.root`), with an `IntersectionObserver`…
observeResizeCalls `callback` each time the size of `element` changes, with a `ResizeObserver` dedicated to it.
prefersReducedMotionWhether the user asked the system to reduce motion (`prefers-reduced-motion: reduce`).
preloadImagesLoads and decodes several images with decodeImage, a few at a time, with `mapSettled` from `helpers4/array`.
watchMediaCalls `listener` each time a CSS media query starts or stops matching.
whenIdleRuns `callback` when the browser is idle, with `requestIdleCallback`, for work that can wait (prefetching, analytics, w…