Skip to content

Commit f70f7ef

Browse files
committed
Add deployment instructions for Brotli support
1 parent 716ac1d commit f70f7ef

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/deployment.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Webpacker doesn't serve anything in production. You’re expected to configure y
4444

4545
Some servers support sending precompressed versions of files with the `.gz` extension when they're available. For example, nginx offers a `gzip_static` directive.
4646

47+
Some servers support sending precompressed versions of files when they're available. For example, nginx offers a `gzip_static` directive that serves files with the `.gz` extension to supported clients. With an optional module, nginx can also serve Brotli compressed files with the `.br` extension (see below for installation and configuration instructions).
48+
4749
Here's a sample nginx site config for a Rails app using Webpacker:
4850

4951
```nginx
@@ -71,11 +73,24 @@ server {
7173
7274
location ^~ /packs/ {
7375
gzip_static on;
76+
brotli_static on; # Optional, see below
7477
expires max;
7578
}
7679
}
7780
```
7881

82+
### Installing the ngx_brotli module
83+
84+
If you wanna serve Brotli compressed files with nginx, you need to install the `nginx_brotli` module. Installation instructions from source can be found in the official [google/ngx_brotli](https://github.com/google/ngx_brotli) repository. Alternatively, depending on your platform, the module might be available via a pre-compiled package.
85+
86+
Once installed, you need to load the module. As we wanna serve pre-compressed files, we only need the static module. Add the following line to your `nginx.conf` file and reload nginx:
87+
88+
```
89+
load_module modules/ngx_http_brotli_static_module.so;
90+
```
91+
92+
Now you can set `brotli_static on;` in your nginx site config, per the config in the last section above.
93+
7994
## CDN
8095

8196
Webpacker out-of-the-box provides CDN support using your Rails app `config.action_controller.asset_host` setting. If you already have [CDN](http://guides.rubyonrails.org/asset_pipeline.html#cdns) added in your Rails app
@@ -106,4 +121,3 @@ namespace :deploy do
106121
end
107122
end
108123
```
109-

0 commit comments

Comments
 (0)