kit icon indicating copy to clipboard operation
kit copied to clipboard

precompress - please add configuration

Open HummingMind opened this issue 2 years ago • 8 comments
trafficstars

Describe the problem

Hello, Precompress could use some configuration settngs for the adapters that support it.

Thank you!

Describe the proposed solution

  1. Allow to disable gzip or brotli. Something like {gzip: false, brotli: true}
  2. 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}
  3. 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

HummingMind avatar Sep 27 '23 01:09 HummingMind

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.

flo-at avatar Jan 16 '24 23:01 flo-at

Allow to control which assets are compressed. Something like {formats: [html, svg, js, css]}

What's the usecase for that?

benmccann avatar Mar 05 '24 22:03 benmccann

More ideas for configuration here: https://github.com/sveltejs/kit/pull/1693#issuecomment-861483732

I'd rather keep things on the simple side though

benmccann avatar Mar 05 '24 22:03 benmccann

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!

HummingMind avatar Mar 06 '24 00:03 HummingMind

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?

benmccann avatar Mar 06 '24 16:03 benmccann

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?

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.

HummingMind avatar Mar 06 '24 18:03 HummingMind

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.

DavidPHH avatar Apr 19 '24 18:04 DavidPHH

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.

jasongitmail avatar Aug 20 '24 00:08 jasongitmail