Skip to content
@drupflare/spool v1.0.0 GitHub
    Preparing search index...

    Type Alias ImageOptions

    what spoolProxy({ images }) takes

    type ImageOptions = {
        cache?: ImageCache | false;
        encoder: ImageEncoder;
        hints?: boolean;
        lazy?: LazyOptions | false;
        maxBytes?: number;
        maxWidth?: number | false;
        minBytes?: number;
        paths?: RegExp;
        png?: PngMode;
        quality?: { default?: number; saveData?: number; slow?: number };
        responsive?: ResponsiveOptions | false;
        timeoutMs?: number | false;
        width?: { fallback?: number };
    }
    Index
    cache?: ImageCache | false

    converted bytes by content hash; default an in-memory cache of 64 MiB, false for none

    encoder: ImageEncoder

    converts the bytes; see tinyimgEncoder

    hints?: boolean

    add Accept-CH to HTML responses so the browser sends the width hints; default true

    lazy?: LazyOptions | false

    Adds loading="lazy" and decoding="async" to <img> tags in HTML after the first skip (default 2), and loading="lazy" to <iframe> tags with iframes; default false, no page is touched for it. See rewriteLazy.

    maxBytes?: number

    largest origin file converted, in bytes; default 15,000,000

    maxWidth?: number | false

    The width ceiling, 1 to 16384, for a request that carries no width hint; default 2560, false for none. A Sec-CH-Width or a viewport and DPR pair wins over it. An image narrower than the ceiling keeps its size.

    minBytes?: number

    smallest origin file converted, in bytes; default 4096, so icons and sprites stay as they are

    paths?: RegExp

    the paths converted, tested against the pathname; default /\.(?:jpe?g|png)$/i

    png?: PngMode

    How a PNG becomes WebP; default 'lossy'. 'lossless' encodes every PNG without loss, and 'auto' encodes a PNG under 200 KB both ways and serves the smaller (a screenshot or a flat graphic is often smaller lossless, a photograph in a PNG is not). A JPEG is always lossy. The mode is part of the cache key and the ETag of a PNG that is not 'lossy'.

    quality?: { default?: number; saveData?: number; slow?: number }

    WebP quality, 1 to 100, by the visitor's connection; defaults 80, 65 for Save-Data: on, 70 for ECT of slow-2g, 2g or 3g

    responsive?: ResponsiveOptions | false

    Adds a srcset of ?spool-w=<width> variants to same-origin <img> tags in HTML, so a browser that sends no Sec-CH-Width (Firefox, Safari) still asks for a smaller file; default false, no page is touched for it. See rewriteResponsive.

    timeoutMs?: number | false

    How long the proxy waits for the encoder, in milliseconds; default 10,000, false to wait without limit. When the time runs out the visitor gets the origin's bytes, and the encoder is left to finish: a result that arrives late is cached for the next request.

    width?: { fallback?: number }

    fallback is the width ceiling for a request that names none; default maxWidth, and it wins over maxWidth when both are set