Make WordPress Core

Opened 4 months ago

Closed 3 months ago

Last modified 6 weeks ago

#65634 closed defect (bug) (fixed)

Text compression is not enabled in the Docker local dev environment

Reported by: westonruter Owned by: westonruter
Priority: normal Milestone: 7.2
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch
Cc: Focuses: performance

Description

I was doing performance testing for #65206 but I was having a difficult time getting results that would be reflective of a user's experience because text compression was not enabled in the web server. On pages with a lot of JavaScript, like the Site Editor, this makes any performance improvements difficult to measure because they are drowned out by many many megabytes of JavaScript.

I suggest we enable gzip compression because it is available in the current Docker image, and it would be more representative of an average WP site compared with having compression turned off.

Change History (7)

This ticket was mentioned in ​PR #12529 on ​WordPress/wordpress-develop by ​@westonruter.


4 months ago
#1

  • Keywords has-patch added

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. curl without --compressed) continues to receive uncompressed responses as before. gzip_vary on ensures caches key on the encoding, and the gzip_types list deliberately omits already-compressed assets (images, woff2 fonts) so nothing is wastefully re-compressed.

Notes:

  • nginx:alpine (the image used by the local environment) ships the gzip module but not brotli, so this uses gzip.
  • Because the nginx template is rendered by envsubst when the container starts, existing checkouts need to restart the web server container to pick up the change (e.g. docker compose restart wordpress-develop).

Verified locally under Fast 4G throttling: the Site Editor's major bundles compress to roughly 30% of their transfer size (e.g. editor.min.js 1.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.

## 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 this PR description, and running the performance measurements that motivated the change. All changes were directed, reviewed, and verified by me.

#2 @westonruter
4 months ago

  • Owner set to westonruter
  • Status new → accepted

This ticket was mentioned in ​Slack in #core-performance by westonruter. ​View the logs.


3 months ago

#4 @westonruter
3 months ago

  • Milestone 7.1 → 7.2

Punting as this can land at any time, being just a dev environment change.

#5 @westonruter
3 months ago

  • Resolution → fixed
  • Status accepted → closed

In 63308:

Build/Test Tools: Allow text compression in the local environment.

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 ​https://github.com/WordPress/wordpress-develop/pull/12529.
Follow-up to r45745, r45783.

Props westonruter, jblz.
Fixes #65634.

​@jblz commented on ​PR #12529:


3 months ago
#6

This is testing well :)

$ curl -sI -H 'Accept-Encoding: gzip' http://localhost:8889/wp-includes/css/dashicons.css | grep -iE 'content-type|content-encoding|vary'
  Content-Type: text/css
  Vary: Accept-Encoding
  Content-Encoding: gzip


$ curl -sI -H 'Accept-Encoding: gzip' http://localhost:8889/wp-includes/images/w-logo-blue.png | grep -iE 'content-type|content-encoding'
  Content-Type: image/png

$ curl -sI -H 'Accept-Encoding: gzip' 'http://localhost:8889/?feed=rss2'
  | grep -iE 'content-type|content-encoding'
  Content-Type: application/rss+xml; charset=UTF-8
  Content-Encoding: gzip

Not a blocker, but noting that specifying a value other than on or off for LOCAL_NGINX_COMPRESSION "silently" breaks nginx in the container. Logs say something like:

wordpress-develop-1 | nginx: [emerg] invalid value "o" in "gzip" directive, it must be "on" or "off" in /etc/nginx/conf.d/default.conf:18

#7 @westonruter
6 weeks ago

In 63946:

Build/Test Tools: Allow far-future caching in the local environment.

Add an expires directive for CSS, JavaScript, font and image files to the nginx config template used by the local Docker environment, so that static asset caching can match normal production behavior. Without it, static files are served with only Last-Modified and ETag, so browsers fall back to a heuristic lifetime of a tenth of each file's age, which in a freshly built checkout is seconds to minutes. Caching then depends on how recently the assets were built, and comparisons with script and style concatenation are skewed, since load-scripts.php and load-styles.php already send a one-year lifetime of their own.

The lifetime is controlled by a new LOCAL_NGINX_STATIC_EXPIRES option, and it defaults to off so that it is opt-in: with most core assets versioned by the WordPress version rather than by their content, a far-future lifetime serves edited files stale until a hard reload. A missing file still falls through to WordPress, so a virtual asset such as the dynamic /favicon.ico keeps working.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13777.
Follow-up to r63308.

See #57548, #65634.
Fixes #66194.

Note: See TracTickets for help on using tickets.