gzip_static serves a file you compressed once

gzip on compresses every response as it is sent, which for a static bundle means doing the same CPU work for every visitor to produce an identical result.

# nginx compresses once per request
gzip on;
gzip_types application/javascript text/css;

# or serve app.js.gz, produced at build time
gzip_static on;

With gzip_static, nginx looks for a .gz next to the file and serves it directly when the client accepts gzip. The build step gains a compression pass — which can afford maximum compression, since it happens once — and the server does none. It falls back to normal gzip when the file is missing, so it is safe to turn on before the build produces them. The module is compiled in on the Ubuntu packages but not on every build.