Skip to content

Enable Brotli pre-compression for static assets#52

Merged
michaeldistel merged 2 commits intomainfrom
40-enable-brotli-compression-alongside-gzip
Feb 14, 2026
Merged

Enable Brotli pre-compression for static assets#52
michaeldistel merged 2 commits intomainfrom
40-enable-brotli-compression-alongside-gzip

Conversation

@michaeldistel
Copy link
Contributor

Summary

  • Build process generates .br files (75% reduction: 1339KB → 333KB)
  • gzip_static enabled for serving pre-compressed gzip files
  • Infrastructure ready for brotli_static when nginx module versions align

Implementation

Build Pipeline:

  • brotli package added for pre-compression
  • compress-brotli.cjs script compresses 44 files at build time
  • Integrated into build:prod (runs after vite build)
  • Skips files <100 bytes

Compression Results:

  • Total: 75.1% reduction
  • Shiki chunk (D6Fn0WwO.js): 698KB → 174KB (75% saved)
  • CSS (app.css): 26KB → 4.4KB (83% saved)
  • HTML pages: 74-80% reduction

Infrastructure:

  • Dockerfile added to deployment files
  • nginx config updated with gzip_static ON
  • brotli_static config ready (commented out due to version mismatch)
  • Nginx config version bumped to 1.3.0

Known Limitation

nginx:alpine 1.29 vs nginx-mod-http-brotli 1.28 version mismatch prevents brotli module loading. .br files generated and ready; will activate automatically when Alpine package updates.

Current: gzip compression working
Future: 15-20% better compression with brotli vs gzip

Testing

  • Local build verified: 44 .br files created
  • Deployment successful: container healthy
  • Site functional: https://controlforge.dev/

Build changes:
- Add brotli package for pre-compression
- Create compress-brotli.cjs script (75% reduction)
- Integrate into build:prod pipeline
- Generate .br files for 44 assets (1339KB → 333KB)
- Skip files <100 bytes

Infrastructure (ready for brotli when nginx versions align):
- Add Dockerfile to deployment
- Update nginx config with brotli_static (commented out)
- Enable gzip_static for gzip pre-compressed files
- Nginx config v1.3.0

Limitation:
nginx:alpine 1.29 vs nginx-mod-http-brotli 1.28 version mismatch
.br files generated and ready; will activate when versions align

Current: gzip compression active
Future: brotli will provide 15-20% better compression than gzip
@michaeldistel michaeldistel linked an issue Feb 14, 2026 that may be closed by this pull request
Changes:
- FROM nginx:1.28.2-alpine (was nginx:alpine latest)
- Install and load nginx-mod-http-brotli modules
- Enable brotli_static and brotli directives in nginx config
- Nginx config version 1.3.0

Result:
- Brotli compression now active (content-encoding: br)
- Serving pre-compressed .br files (75% smaller)
- Gzip fallback for old browsers

Version pinning necessary until Alpine updates nginx-mod-http-brotli to 1.29+
@michaeldistel
Copy link
Contributor Author

Fixed - Brotli now active!

Pinned nginx to 1.28.2-alpine to match Alpine's brotli module version.

Verified working:

$ curl -sI -H "Accept-Encoding: br" https://controlforge.dev/_app/immutable/chunks/D6Fn0WwO.js | grep content-encoding
content-encoding: br

Files served:

  • .br files: 173.8KB (Shiki bundle)
  • vs original: 698.3KB
  • 75% reduction

Created #53 as reminder to upgrade when Alpine package updates.

@michaeldistel michaeldistel merged commit 5451baa into main Feb 14, 2026
@michaeldistel michaeldistel deleted the 40-enable-brotli-compression-alongside-gzip branch February 14, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable Brotli compression alongside gzip

1 participant