tinyserve works. To be fast, it must avoid sending what the browser already has, and compress
what it sends. The starter is the solution of *Serve Static Files*; extend it.
For every file it is about to serve with 200:
ETag: W/"<size in hex>-<mtime in ms, rounded down, in hex>", from fs.stat — e.g. W/"12-18cc251f400".
Cache-Control: no-cache for HTML (text/html...), public, max-age=3600 foreverything else.
Vary: Accept-Encoding when the type is compressible: text/*, application/json, image/svg+xml.
If the request's If-None-Match (a comma-separated list) contains that ETag or *, answer
304 with only ETag, Cache-Control and Vary (when it applies), and no body.
When the type is compressible and Accept-Encoding accepts gzip, sendContent-Encoding: gzip, no Content-Length (the compressed size is unknown in advance), and
pipe the file through zlib.createGzip(). Otherwise keep Content-Length and send the file
as is.
Accept-Encoding is a comma-separated list of codings, matched case-insensitively, each with
optional parameters: gzip;q=0 means gzip is refused, any other q accepts it.
HEAD gets exactly the headers of GET, without body. Everything else (405, 404, 301...)
behaves as before. The driver fixes every file's mtime to 2024-01-01 and gunzips gzip bodies
before reporting them.
Sample tests