nonzzz / vite-plugin-compression

vite plugin. compress your bundle file.
MIT License
162 stars 9 forks source link

Add feature: skip compressed file if it's larger than or equal to original #32

Closed vHeemstra closed 1 year ago

vHeemstra commented 1 year ago

This PR adds the option to skip outputting the compressed file if it is larger than or equal to the original file. This is on by default, but can be disabled using option skipIfLargerOrEqual: false.

Reason for adding this: Compressing assets is to reduce site traffic (amount) which improves load time in turn. However, if the compressed file is larger than (or equal to) the original file, there is no benefit, so skipping seems more appropriate then.

(Oh, and I fixed a typo)

vHeemstra commented 1 year ago

If you need a file to test this functionality, I used a .woff2 web font file from Nunito on Google Fonts. This file can be found here.

The compressed version of this file (either GZip or Brotli) is 1 byte larger than the original, so it should be skipped if skipIfLargerOrEqual is true.

nonzzz commented 1 year ago

LGTM. I'll let the tests run before merging the code

nonzzz commented 1 year ago

I set skipIfLargerOrEqual as false. When we set true as default it will break most of test case :(

nonzzz commented 1 year ago

@vHeemstra cc

vHeemstra commented 1 year ago

I set skipIfLargerOrEqual as false. When we set true as default it will break most of test case :(

That's fine too.

Maybe it breaks the test cases because their compressed output is larger than or equal to the original content?

nonzzz commented 1 year ago

Yes. previous test case don't support it. So i write a new test case.

nonzzz commented 1 year ago

The v0.10.0 has been released