Skip to content

Commit dd59813

Browse files
committed
Add example for setting :asset_host as Proc
[ci skip]
1 parent db6dda5 commit dd59813

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ These configurations are configured via an option hash:
6464
* `:digests` - Set a hash used for file name lookup. This will be default to Rails' manifest at `Rails.configuration.assets.digests`.
6565
* `:prefix` - Set a path prefix of your assets file. This will be default to `Rails.configuration.assets.prefix` (usually at `/assets`.)
6666
* `:manifest` - Set a path to your own manifest file to use for lookup. This will override both `:digest` hash and `Sprockets::Redirect.manifest` setting.
67-
* `:asset_host` - Set the name of the host to use when serving assets. This is useful if you want your server to redirect to assets that are hosted on a CDN.
67+
* `:asset_host` - Set the name of the host to use when serving assets. This is useful if you want your server to redirect to assets that are hosted on a CDN. You can also passing a `Proc` object which will be called on every asset requests to determine the host for that request:
68+
69+
config.middleware.swap Sprockets::Redirect,
70+
Sprockets::Redirect,
71+
:asset_host => Proc.new do |request|
72+
if request.path =~ /\.min\.(js|css)\z/
73+
"cdn.example.com"
74+
end
75+
end
6876

6977
You can swap out the middleware inserted automatically by the gem by using `config.middleware.swap` in your configuration file:
7078

0 commit comments

Comments
 (0)