tokers / zstd-nginx-module

Nginx modules for the Zstandard compression
BSD 2-Clause "Simplified" License
196 stars 23 forks source link

Issues with compression not working with browsers #35

Closed Vortetty closed 2 months ago

Vortetty commented 4 months ago

I have the module set up with nginx, compiled statically and running locally with the config here for testing. It appears that even with small content like this i am running into issues with zstd not being supported in most browsers. That said it works fine in other utilities such as curl. Firefox gives a generic "Unsupported compression method" error page, and chromium-based browsers show a blank page with a net::ERR_ZSTD_WINDOW_SIZE_TOO_BIG error. Are there any ways currently to fix this issue? Lowering the compression level to 19 seems to be a solution, but i would love to be able to go all the way up to 22 assuming my server has the capacity in the future.

I'd be happy to debug more as well and/or provide more info if asked. If it's unavoidable with the higher compression levels i might recommend just adding a note in the readme that higher levels may cause issues with browsers, in case others run into this as well :)

notr1ch commented 2 months ago

This is apparently the intended behavior in Chrome so that servers can't place unreasonable memory demands on clients (see https://source.chromium.org/chromium/chromium/src/+/2387048271c6d95b4985f8287ba83b97bc625bfb). Never mind that Javascript could be used to allocate gigabytes of memory 🙄

The zstd docs also make note of this:

Levels >= 20, labeled --ultra, should be used with caution, as they require more memory.

Vortetty commented 2 months ago

i noticed that a bit after, it seems that with compression level 19 browsers occasionally fail as well, the safe minimum seems to be 12-14 which is a bit odd

it would be nice if they documented that but it is what it is, seems to not actually be an issue with this nginx extension though after more testing