Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Compression #3

Closed
4 tasks
lukeed opened this issue May 13, 2018 · 4 comments
Closed
4 tasks

File Compression #3

lukeed opened this issue May 13, 2018 · 4 comments
Labels
enhancement New feature or request has fix
Milestone

Comments

@lukeed
Copy link
Owner

lukeed commented May 13, 2018

As a convenience, sirv-cli should compress your files on startup. This would happen only once, immediately before using tiny-glob to read & cache the files.

I'm 90% sure the compression would have to be file-by-file, rather than doing the entire directory at once. This is because we'd have to see if the foobar.{hash}.gz (or whatever) file exists first, and only produce a compressed version if it doesn't exist... otherwise ETag values would be wrong.

🤔 Maybe run tiny-glob first after all? Then do a lookup on the returned results. Then, either rerun tiny-glob (since it'll still have its CACHE handy) or append our compressed outputs to the original set.

The sirv module should also take a compress option. It won't do any compressing (since it's the runtime), but it'll prefer/look to serve the compressed file over the original.

Allowed Values:

  • gzip (default)
  • brotli
  • zopfli

CLI Flags

  • -c, --compress, 'Enable file compression with specified format', 'gzip'
@lukeed lukeed added the enhancement New feature or request label May 13, 2018
@lukeed lukeed added this to the 0.2.0 milestone May 14, 2018
@cjk
Copy link

cjk commented Jul 15, 2019

I would be interested in this feature. Is this still being worked on?
Serving compressed files would make a huge difference for me. I'm using Polka + sirv and don't want to switch to Fastify / Express just to get compressed payloads.

@CryptoKiddies
Copy link

This would be great for me as well. Can't serve my gzipped js files.

@lukeed lukeed added the has fix label Sep 28, 2019
lukeed added a commit that referenced this issue Sep 28, 2019
lukeed added a commit that referenced this issue Sep 28, 2019
- still optimized
- adds ETag support to "dev" mode
- adds brotli/gzip support to "dev" mode
- Related: #3
@lukeed
Copy link
Owner Author

lukeed commented Sep 29, 2019

Available in current @next versions of the libs. They are toggled individually through opts.gzip and opts.brotli – or -G/--gzip and -B/--brotli for the CLI.

Decided not to include zopfli – at least at this time.

When enabled, sirv will try to serve a precompiled version of your file(s) to the client if they support it. So, for example, if the request for /bundle.js has the Accept-Encoding: br, gzip header, then sirv will look for bundle.js.br (if --brotli enabled) and then for bundle.js.gz (if --gzip enabled) before defaulting to the bundle.js file.

@cjk
Copy link

cjk commented Sep 30, 2019

@lukeed This is great news - thanks for the addition!

@lukeed lukeed closed this as completed in bb948a7 Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has fix
Projects
None yet
Development

No branches or pull requests

3 participants