mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
asset pipeline guide: removes Apache config for serving pre-compressed 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.
This commit is contained in:
parent
3088d23647
commit
b1c20e37ec
1 changed files with 12 additions and 21 deletions
|
@ -438,26 +438,7 @@ 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.
|
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:
|
Nginx is able to do this automatically enabling +gzip_static+:
|
||||||
|
|
||||||
<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:
|
|
||||||
|
|
||||||
<plain>
|
<plain>
|
||||||
location ~ ^/(assets)/ {
|
location ~ ^/(assets)/ {
|
||||||
|
@ -468,6 +449,16 @@ location ~ ^/(assets)/ {
|
||||||
}
|
}
|
||||||
</plain>
|
</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
|
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.
|
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.
|
||||||
|
|
Loading…
Reference in a new issue