Skip to content

Commit

Permalink
asset pipeline guide: removes Apache config for serving pre-compresse…
Browse files Browse the repository at this point in the history
…d assets, and expands the information about nginx support for this

A robust Apache configuration for this feature seems to be tricky,
one that takes into account Accept-Encoding, sets Vary, ensures
Content-Type is right, etc.
  • Loading branch information
fxn committed Oct 7, 2011
1 parent 7bf12a1 commit be6527f
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions railties/guides/source/asset_pipeline.textile
Expand Up @@ -438,36 +438,27 @@ location ~ ^/assets/ {

When files are precompiled, Sprockets also creates a "gzipped":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. One the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.

A possible configuration for Apache could be:

<plain>
<LocationMatch "^/assets/.*$">
# 2 lines to serve pre-gzipped version
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
</LocationMatch>

# without these, Content-Type will be "application/x-gzip"
<FilesMatch "^/assets/.*\.css.gz$">
ForceType text/css
</FilesMatch>

<FilesMatch "^/assets/.*\.js.gz$">
ForceType text/javascript
</FilesMatch>
</plain>

For nginx:
Nginx is able to do this automatically enabling +gzip_static+:

<plain>
location ~ ^/(assets)/ {
root /path/to/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
add_header Cache-Control public;
}
</plain>

This directive is available if the core module that provides this feature was compiled with the web server. Ubuntu packages, even +nginx-light+ have the module compiled. Otherwise, you may need to perform a manual compilation:

<plain>
./configure --with-http_gzip_static_module
</plain>

If you're compiling nginx with Phusion Passenger you'll need to pass that option when prompted.

Unfortunately, a robust configuration for Apache is possible but tricky, please Google around.

h4. Live Compilation

In some circumstances you may wish to use live compilation. In this mode all requests for assets in the pipeline are handled by Sprockets directly.
Expand Down

0 comments on commit be6527f

Please sign in to comment.