Skip to content

Commit a216db6

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

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

docs/deployment.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Deployment
22

33

4-
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`.
4+
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`.
55
If you are not using Sprockets `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set NODE_ENV environment variable to production during deployment or when running the rake task.
66

77
The `javascript_pack_tag` and `stylesheet_pack_tag` helper method will automatically insert the correct HTML tag for compiled pack. Just like the asset pipeline does it.
@@ -34,15 +34,15 @@ We're essentially doing the following here:
3434

3535
* Creating an app on Heroku
3636
* Creating a Postgres database for the app (this is assuming that you're using Heroku Postgres for your app)
37-
* Adding the Heroku NodeJS and Ruby buildpacks for your app. This allows the `npm` or `yarn` executables to properly function when compiling your app - as well as Ruby.
37+
* Adding the Heroku NodeJS and Ruby buildpacks for your app. This allows the `npm` or `yarn` executables to properly function when compiling your app - as well as Ruby.
3838
* Pushing our code to Heroku and kicking off the deployment
3939

4040

4141
## Nginx
4242

4343
Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
4444

45-
Some servers support sending precompressed versions of files with the `.gz` extension when they're available. For example, nginx offers a `gzip_static` directive.
45+
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).
4646

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

@@ -71,11 +71,24 @@ server {
7171
7272
location ^~ /packs/ {
7373
gzip_static on;
74+
brotli_static on; # Optional, see below
7475
expires max;
7576
}
7677
}
7778
```
7879

80+
### Installing the ngx_brotli module
81+
82+
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.
83+
84+
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:
85+
86+
```
87+
load_module modules/ngx_http_brotli_static_module.so;
88+
```
89+
90+
Now you can set `brotli_static on;` in your nginx site config, per the config in the last section above.
91+
7992
## CDN
8093

8194
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 +119,3 @@ namespace :deploy do
106119
end
107120
end
108121
```
109-

0 commit comments

Comments
 (0)