运行 assets:precompile rake 任务时,会创建应用资产的压缩版本。根据资产管道的 Rails 指南,您可以配置您的 Web 服务器(在我的情况下为 Apache 2.2)来提供这些预压缩文件,而不是让 Web 服务器完成工作。
我想不通的是如何配置 mod_deflate 以便提供这些文件而不是双重压缩然后提供?
我通过 httpd.conf 启用了 mod_deflate:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
我已经将 rails 指南上的代码转换为 public/assets 中的 .htaccess :
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
Header unset Last-Modified
Header unset ETag
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
# Serve gzipped versions instead of requiring Apache to do the work
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
# without it, Content-Type will be "application/x-gzip"
<FilesMatch .*\.css.gz>
ForceType text/css
</FilesMatch>
<FilesMatch .*\.js.gz>
ForceType text/javascript
</FilesMatch>
任何想法如何正确设置?