Docker, nginx, SPA and brotli compression
Contemporary web development separates front-end and back-end, resulting in the front-end being a few static files. Besides setting long cache headers, pre-compression is one way to speed up delivery
Setting the stage
- we have a NodeJS project that outputs our SPA in
/usr/dist
directory. Highly recommended here: VITE. Works for multi-page applications too. - We target only modern browsers that understand brotli (Sorry not IE). Legacy will have to deal with uncompressed files
- We want to go light on CPU, so we compress at build time, not runtime
Things to know
- When nginx is configured for brotli and the file
index.html
gets requested, the fileindex.html.br
gets served if present and the browser indicated (what it does by default) that it can accept br - There are tons of information about the need to compile nginx due to the lack of brotli support out of the box. That's not necessary (see below)
- brotli is both OpenSource and the open standard RFC 7932
- brotli currently lacks gzip's
-r
flag, so some bash magic is needed
Moving parts
- DockerFile
- nginx configuration
The Dockerfile will handle the brotli generation
Read more
Posted by Stephan H Wissel on 24 June 2023 | Comments (0) | categories: Docker nginx WebDevelopment