kit
kit copied to clipboard
precompress - please add configuration
Describe the problem
Hello, Precompress could use some configuration settngs for the adapters that support it.
Thank you!
Describe the proposed solution
- Allow to disable gzip or brotli. Something like {gzip: false, brotli: true}
- Add a minimum size of the assets that should be compressed. For example, do not compress anything under 1024 bytes. Compressing these tiny files can actually make them larger. Something like {minSize: 1024}
- Allow to control which assets are compressed. Something like {formats: [html, svg, js, css]}
Alternatives considered
No response
Importance
nice to have
Additional Information
No response
I just found this issue while trying to find out how to configure the precompress task. Instead of (or in addition to) the minimum size option, imo an option to delete the files that end up being larger than their uncompressed version would be better. The minimum size is a guessing game and it depends on the content of the file, too.
Allow to control which assets are compressed. Something like {formats: [html, svg, js, css]}
What's the usecase for that?
More ideas for configuration here: https://github.com/sveltejs/kit/pull/1693#issuecomment-861483732
I'd rather keep things on the simple side though
Allow to control which assets are compressed. Something like {formats: [html, svg, js, css]}
What's the usecase for that?
Probably not as important as # 1 and # 2, but it would allow for additional flexibility.
Looks like html, js, json, css, svg, xml are currently compressed. There may be additional asset fromats that could benefit. (.txt or .csv) for example. Probably always better to let the user control and override the default choices or add additional formats.
Thank you!
Looks like html, js, json, css, svg, xml are currently compressed.
Actually the code has ['.html', '.js', '.mjs', '.json', '.css', '.svg', '.xml', '.wasm']. Yes, it could make sense to make this configurable.
Allow to disable gzip or brotli. Something like {gzip: false, brotli: true}
I guess you might not need to create gzip if you don't support older browsers, but why would you want to be able to disable brotli?
Looks like html, js, json, css, svg, xml are currently compressed.
Actually the code has
['.html', '.js', '.mjs', '.json', '.css', '.svg', '.xml', '.wasm']. Yes, it could make sense to make this configurable.Allow to disable gzip or brotli. Something like {gzip: false, brotli: true}
I guess you might not need to create
gzipif you don't support older browsers, but why would you want to be able to disable brotli?
Personally, I am using brotli and would not want to disable it. Not sure if anyone else has a use case for doing that. I would be OK with having the option to disable only gzip.
I have to disable precompress entirely because Bun doesn't have zlib.createBrotliCompress implemented yet (issue)
Would be neat to have the option to just disable brotli.
Useful site to estimate KB savings for your site based on compression level: https://tools.paulcalvano.com/compression.php https://tools.paulcalvano.com/compression-tester/
For my SvelteKit site, max brotli would save 15-20% over Cloudflare's default brotli level (4). zstd would be even more.
@DavidPHH bun supports now via node:zlib.