aphid 0.5.0
aphid 0.5.0 is about compression. aphid-server now sends text responses compressed, and a new build flag, aphid build --precompress, does the compression once at build time. There are no breaking changes.
Compressed responses in aphid-server
HTML, CSS, JavaScript, SVG, feeds and other text responses are compressed with brotli or gzip, whichever the client’s Accept-Encoding prefers. There is nothing to configure: upgrade the image and it is on.
- Images other than SVG and very small bodies are sent as they are.
- A client that sends no
Accept-Encodinggets the original file. - If the reverse proxy in front already compresses, nothing is compressed twice.
On its own, the server compresses each response as it is requested and caches nothing. That is fine for a small site, and the next section removes the work entirely.
Precompression with aphid build --precompress
With the flag, the build writes a brotli and a gzip variant next to every text file of at least 1 KiB (index.html → index.html.br, index.html.gz) and keeps the originals. aphid-server sends a matching variant as it is, with its Content-Length, and falls back to compressing on the fly for anything without one.
Because this runs once per build, it uses the highest compression levels. On this documentation site the build takes about one second instead of 0.2, and the output grows from 12 MB to 14 MB.
The flag is off by default. Hosts that don’t know the convention, GitHub Pages among them, ignore the extra files, so only turn it on for a site served by aphid-server. The GitHub Action has a matching precompress input:
- uses: LHelge/aphid@main
with:
precompress: true
See Serving with aphid-server for how the server picks a variant and CLI reference for the flag.
Other changes
- The access log’s
bytesfield is the size of the file sent: the compressed size for a precompressed file, and the size before compression for a response compressed on the fly. - For library users,
aphid::build_withtakes aBuildOptionsvalue;aphid::buildis unchanged.
Upgrading
For a containerised site, bump the image tag and add the flag to the build:
FROM ghcr.io/lhelge/aphid-server:0.5.0
COPY dist /site
LHelge