Skip to content

Commit 1fcc5c0

Browse files
committed
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 WordPress#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
1 parent e7739d5 commit 1fcc5c0

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ LOCAL_PORT=8889
1414
# Where to run WordPress from. Valid options are 'src' and 'build'.
1515
LOCAL_DIR=src
1616

17+
# Whether or not to enable text compression (gzip) in the web server.
18+
# Valid options are 'on' and 'off'.
19+
LOCAL_NGINX_COMPRESSION=off
20+
1721
# The PHP version to use. Valid options are 'latest', and '{version}-fpm'.
1822
LOCAL_PHP=latest
1923

‎docker-compose.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ services:
1414

1515
environment:
1616
LOCAL_DIR: ${LOCAL_DIR-src}
17+
LOCAL_NGINX_COMPRESSION: ${LOCAL_NGINX_COMPRESSION:-off}
1718

1819
volumes:
1920
- ./tools/local-env/default.template:/etc/nginx/conf.d/default.template
2021
- ./:/var/www
2122

2223
# Load our config file, substituting environment variables into the config.
23-
command: /bin/sh -c "envsubst '$$LOCAL_DIR' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
24+
command: /bin/sh -c "envsubst '$$LOCAL_DIR $$LOCAL_NGINX_COMPRESSION' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
2425

2526
depends_on:
2627
php:

‎tools/local-env/default.template‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ server {
1515

1616
absolute_redirect off;
1717

18+
gzip ${LOCAL_NGINX_COMPRESSION};
19+
gzip_vary on;
20+
gzip_proxied any;
21+
gzip_comp_level 5;
22+
gzip_min_length 256;
23+
gzip_types
24+
application/javascript
25+
text/javascript
26+
application/json
27+
application/xml
28+
application/rss+xml
29+
text/css
30+
text/plain
31+
image/svg+xml;
32+
1833
if (!-e $request_filename) {
1934
rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
2035
rewrite ^(/[^/]+)?(/wp-.*) $2 last;

0 commit comments

Comments
 (0)