h5bp / server-configs-nginx

Nginx HTTP server boilerplate configs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimal NGINX gzip_min_length tuned for performance?

LukaszJaro opened this issue · comments

Hi,

Seems to be bunch of data stating that compressing files over 1400 bytes is pointless due to the MTU being able to handle 1400 bytes max.

Here's a short discussion on it https://webmasters.stackexchange.com/questions/89943/should-i-compress-very-small-html-pages

Current boilerplate config is much less than that but I'm wondering is this optimal for performance( response time). Example is a autocomplete search using ajax(xhr) which returns 1.3kb uncompressed and 1.2kb compressed, depending on how aggressive the compression level is. Would this cause a slower response to the client due to compressing/cpu usage and better to not have any gzip encoding for such small responses?

# Don't compress anything that's already small and unlikely to shrink much if at
# all (the default is 20 bytes, which is bad as that usually leads to larger
# files after gzipping).
# Default: 20
gzip_min_length 256;

Thanks for opening this issue @LukaszJaro.
That being said I'm not sure it is the good place to ask such question...

Anyway, usually for the modern web, we consider that computer hosting browser are no more from 2000's and can handle compression much faster than latency + bitrate of network.

Regarding the server, if you want to optimize the optimization, it is actually recommended to compress at a build time and not jit.
H5BP does contain a template to handle that case (with the equivalent for brotli):

# ----------------------------------------------------------------------
# | GZip pre-compressed content |
# ----------------------------------------------------------------------
# Serve gzip compressed CSS, JS, HTML, SVG, ICS, and JSON files if they exist
# and if the client accepts gzip encoding.
#
# (!) To make this part relevant, you need to generate encoded files by your
# own. Enabling this part will not auto-generate gziped files.
#
# https://nginx.org/en/docs/http/ngx_http_gzip_static_module.html
gzip_static on;