Skip to content

Commit

Permalink
Add deployment instructions for Brotli support
Browse files Browse the repository at this point in the history
  • Loading branch information
clupprich committed Sep 11, 2019
1 parent 716ac1d commit f70f7ef
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion docs/deployment.md
Expand Up @@ -44,6 +44,8 @@ Webpacker doesn't serve anything in production. You’re expected to configure y

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

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).

Here's a sample nginx site config for a Rails app using Webpacker:

```nginx
Expand Down Expand Up @@ -71,11 +73,24 @@ server {
location ^~ /packs/ {
gzip_static on;
brotli_static on; # Optional, see below
expires max;
}
}
```

### Installing the ngx_brotli module

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.

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:

```
load_module modules/ngx_http_brotli_static_module.so;
```

Now you can set `brotli_static on;` in your nginx site config, per the config in the last section above.

## CDN

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
Expand Down Expand Up @@ -106,4 +121,3 @@ namespace :deploy do
end
end
```

0 comments on commit f70f7ef

Please sign in to comment.