0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Responsive image helper: measures an image's rendered width into sizes, generates srcset from a widths shorthand, and shows an optional dev badge naming the selected source.
Overview
data-responsive on an <img> helps with the two parts of responsive images that are easy to get wrong: a sizes value that matches the real layout, and a long srcset. It measures the image's rendered width and writes it to sizes, and a list of widths (data-responsive="400,800,1200") generates the srcset from the src file name.
Usage
The best baseline needs no JavaScript at all: write the srcset in markup and, for lazy images, let the browser measure with sizes="auto" (Chromium 126+; the value after the comma is the fallback for other browsers).
Empty: measure sizes only. Widths (e.g. "400,800,1200"): also generate srcset from src.
data-responsive-debug
boolean
Show a dev badge beside the image with the selected file name and its natural width. Remove it for production.
Measured sizes
Only images whose srcset uses width descriptors (400w) are measured; x descriptors do not use sizes.
An authored sizes is respected. The exception is auto: on a loading="lazy" image it is left to the browser; on an eager image (where auto is invalid) the width is measured instead.
sizes only grows. When the slot gets narrower the larger candidate is already downloaded, and re-selecting on every resize could feed back into the layout (a new source changes the box, which changes the width again).
An image that fails to load is no longer measured.
Srcset shorthand
The shorthand inserts -{width} before the extension of the last path segment; the query string and hash are kept. /img/photo.jpg?v=2 with 400,800 produces /img/photo-400.jpg?v=2 400w, /img/photo-800.jpg?v=2 800w (as absolute URLs).
An authored srcset wins: the shorthand is ignored.
A file name without an extension (https://images.example.com/photos/abc) is left alone, with a console warning.
Every generated file must exist. The shorthand cannot check, and a missing candidate is a broken image.
The script runs after the HTML parser has already requested src. So:
The shorthand costs a second request when the chosen candidate differs from src. Write the srcset in markup when that matters.
loading and fetchpriority must be in the markup to have any effect. The script only adds decoding="async" when it is missing.
Events
None.
Styling
The debug badge is a span[data-responsive-badge] inserted before the image (or before its <picture>, never inside it). It is absolutely positioned at the inline-start corner; its parent gets position: relative through CSS while the badge is present.
Accessibility
The attribute changes which file loads, not what the image means: write the same alt you would without it.
Give images width and height attributes so space is reserved before they load (no layout shift).
The debug badge is aria-hidden.
Examples
Above-the-fold hero
Eager images cannot use sizes="auto", so this is where measuring helps most. Put fetchpriority in the markup: