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

    Function convertImage

    • Answers one origin response to a request that passed imageRequest: a 200 JPEG or PNG that sets no cookie and is between minBytes and maxBytes becomes WebP, and anything else comes back as it was. The conversion keeps the origin's Cache-Control, merges IMAGE_VARY into Vary, sets a weak ETag from the origin bytes, the quality and the width, and answers 304 when the request's If-None-Match matches it. X-Spool-Image reads <bytesIn>-><bytesOut>; q=<quality>; w=<width or 0>. With responsive, a listed spool-w in the request URL lowers the width to at most that value; an unlisted one is ignored. A PNG follows png.

      The origin is fetched for every request, so a visitor only ever gets the bytes the origin sent that visitor. An encoder that throws, runs past timeoutMs, or produces output that is not smaller serves the origin's bytes with a 200. The response never fails because of the conversion. Simultaneous requests for the same bytes, quality and width share one encoder call.

      Parameters

      Returns Promise<Response>