Build/Test Tools: Enable text compression in the local Docker environment - #12529
Build/Test Tools: Enable text compression in the local Docker environment#12529westonruter wants to merge 6 commits into
Conversation
…ment. Add gzip directives to the nginx config template used by the local Docker environment so that HTML, JavaScript, CSS, JSON, XML, and SVG responses are served compressed. This matches the behavior of virtually all production WordPress hosts and makes front-end performance analysis against the local environment representative: without it, the site editor's ~8 MB of editor JavaScript is served uncompressed, so page-load metrics like LCP are dominated by transfer of dev assets that would be compressed in production. Compression only applies when the client sends `Accept-Encoding: gzip`, so existing uncompressed workflows are unaffected. `gzip_vary on` ensures caches key on the encoding. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Add a `LOCAL_NGINX_COMPRESSION` option (valid values `on`/`off`, defaulting to `on`) that controls whether the web server serves compressed responses. The value is substituted into the nginx template the same way as `LOCAL_DIR`, so it can be set to `off` to reproduce uncompressed behavior for comparison. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR enables gzip text compression in the local Docker nginx configuration so the local environment better reflects typical production hosting behavior and yields more representative front-end performance measurements.
Changes:
- Adds gzip configuration (vary/proxied/level/min length + content types) to the nginx config template used by the local environment.
- Introduces
LOCAL_NGINX_COMPRESSION(defaulton) as a.env/Compose-controlled toggle for enabling/disabling compression. - Updates the container startup command to substitute the new variable into the nginx config via
envsubst.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tools/local-env/default.template | Enables gzip compression in the nginx server config template with a variable-driven on/off toggle. |
| docker-compose.yml | Adds LOCAL_NGINX_COMPRESSION to the web container environment and includes it in envsubst substitution. |
| .env.example | Documents the new LOCAL_NGINX_COMPRESSION option and its valid values. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
jblz
left a comment
There was a problem hiding this comment.
I think we should consider having LOCAL_NGINX_COMPRESSION default to off.
While negligible, compression and decompression in a local env will add overhead that is likely only useful when developing features that depend on that behavior.
Co-authored-by: Jeff Bowen <jblz@users.noreply.github.com>
Co-authored-by: Jeff Bowen <jblz@users.noreply.github.com>
Switch `LOCAL_NGINX_COMPRESSION` to the `:-` form of parameter expansion, so
the default applies when the variable is set but empty as well as when it is
unset entirely.
The value is substituted straight into the nginx template as
`gzip ${LOCAL_NGINX_COMPRESSION};`, so an empty value rendered `gzip ;` and
nginx refused to start with "invalid number of arguments in gzip directive".
Clearing the value in `.env` is an intuitive way to turn compression off, and
it now yields `off` rather than a crash-looping web container.
Co-authored-by: Jeff Bowen <jblz@users.noreply.github.com>
Add gzip directives to the nginx config template used by the local Docker environment so that HTML, JavaScript, CSS, JSON, XML, and SVG responses can be served compressed, matching normal production behavior. Without compression, frontend performance analysis against the local environment is not representative of a real user's experience. Compression is controlled by a new `LOCAL_NGINX_COMPRESSION` option, and it defaults to `off` so that it is opt-in. Since this changes `docker-compose.yml` in addition to the nginx template, existing checkouts need to recreate the web server container to pick up the change. Developed in #12529. Follow-up to r45745, r45783. Props westonruter, jblz. Fixes #65634. git-svn-id: https://develop.svn.wordpress.org/trunk@63308 602fd350-edb4-49c9-b593-d223f7449a82
|
This is testing well :) Not a blocker, but noting that specifying a value other than
|
Add gzip directives to the nginx config template used by the local Docker environment so that HTML, JavaScript, CSS, JSON, XML, and SVG responses can be served compressed, matching normal production behavior. Without compression, frontend performance analysis against the local environment is not representative of a real user's experience. Compression is controlled by a new `LOCAL_NGINX_COMPRESSION` option, and it defaults to `off` so that it is opt-in. Since this changes `docker-compose.yml` in addition to the nginx template, existing checkouts need to recreate the web server container to pick up the change. Developed in WordPress/wordpress-develop#12529. Follow-up to r45745, r45783. Props westonruter, jblz. Fixes #65634. Built from https://develop.svn.wordpress.org/trunk@63308 git-svn-id: http://core.svn.wordpress.org/trunk@62501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Enables gzip compression in the nginx config template used by the local Docker environment, so that HTML, JavaScript, CSS, JSON, XML, and SVG responses are served compressed.
Without this, front-end performance analysis against the local environment is not representative of a real user's experience: on JavaScript-heavy screens like the Site Editor, several megabytes of uncompressed editor JavaScript are transferred on every load, and any performance improvement under test is drowned out by that transfer. Serving compressed responses matches the behavior of virtually all production WordPress hosts.
Compression is
Accept-Encoding-gated, so any request that does not advertise gzip support (e.g.curlwithout--compressed) continues to receive uncompressed responses as before.gzip_vary onensures caches key on the encoding, and thegzip_typeslist deliberately omits already-compressed assets (images, woff2 fonts) so nothing is wastefully re-compressed.Configuration
Compression is enabled by default and controlled by a new
LOCAL_NGINX_COMPRESSIONoption in.env(valid valueson/off, defaulting toon). The value is substituted into the nginx template the same way asLOCAL_DIR. Setting it tooffreproduces the previous uncompressed behavior, which is useful for measuring the uncompressed baseline when comparing performance:Notes
nginx:alpine(the image used by the local environment) ships the gzip module but not brotli, so this uses gzip.docker-compose.yml(the web server's environment and command) in addition to the nginx template, existing checkouts need to recreate the web server container to pick up the change, e.g.docker compose up -d wordpress-developornpm run env:start.Verification
Verified locally under Fast 4G throttling: the Site Editor's major bundles compress to roughly 30% of their transfer size (e.g.
editor.min.js1.55 MB → 498 KB), which brought this screen's LCP down from ~25.4 s to ~15.4 s and made data-loading differences measurable rather than being swamped by asset transfer. TogglingLOCAL_NGINX_COMPRESSIONbetweenonandoffwas confirmed to add/remove theContent-Encoding: gzipresponse header as expected.Trac ticket: https://core.trac.wordpress.org/ticket/65634
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Authoring the nginx gzip configuration and the
LOCAL_NGINX_COMPRESSIONtoggle, drafting this PR description, and running the performance measurements that motivated the change. All changes were directed, reviewed, and verified by me.