Skip to content
This repository
Browse code

[asset pipeline] Add section on sendfile option

This option has caught a few people out, so it
is a good idea to include an explanation and
a Gotcha.

See Rails bug 1822
See 1822 comment 1585926 for resolution
  • Loading branch information...
commit 0d30929a9156fbf01911ce9639f9bb47630d4aab 1 parent 06636c5
Richard Hulse rhulse authored fxn committed

Showing 1 changed file with 14 additions and 0 deletions. Show diff stats Hide diff stats

  1. +14 0 railties/guides/source/asset_pipeline.textile
14 railties/guides/source/asset_pipeline.textile
Source Rendered
@@ -367,6 +367,20 @@ config.assets.prefix = "/some_other_path"
367 367
368 368 This is a handy option if you have any existing project (pre Rails 3.1) that already uses this path.
369 369
  370 +h4. X-Sendfile headers
  371 +
  372 +The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the server to do work. Files are faster served by the webserver. Both Apache and nginx support this option.
  373 +
  374 +New applications contain this line in +production.rb+
  375 +
  376 +<erb>
  377 +config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
  378 +</erb>
  379 +
  380 +You should check that your server or hosting service actually supports this, otherwise comment it out.
  381 +
  382 +Gotcha: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+ ).
  383 +
370 384 h3. How caching works
371 385
372 386 Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is filenames are fingerprinted and get far-future headers in production.

0 comments on commit 0d30929

Please sign in to comment.
Something went wrong with that request. Please try again.