Sprockets::Sidecar
Writes precompressed sidecar files (.br, .zst) next to sprockets assets.
This is a fork of sprockets-exporters_pack gem that adds support of Zstd compression and asset cleanup.
Currently, it has:
- a Brotli exporter, which can be used with Nginx ngx_brotli module and Caddy file_server.precompressed subdirective.
- a Zstd exporter, which can be used with Nginx zstd-nginx-module module and Caddy file_server.precompressed subdirective.
Installation
Add this line to your Gemfile:
gem 'sprockets-sidecar'If you used sprockets-exporters_pack before, remove it from your Gemfile and replace Sprockets::ExportersPack with Sprockets::Sidecar.
You probably need these too, as sprockets hasn't been updated yet:
gem 'sprockets', '>= 4.0.0.beta3', github: 'rails/sprockets'
gem 'sprockets-rails', '>= 3.1.0'bundle installUsage
With Rails, in application.rb:
config.assets.configure do |env|
# Brotli
env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::Sidecar::BrotliExporter
# Zstd
env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::Sidecar::ZstdExporter
endWithout Rails:
env = Sprockets::Environment.new
# Brotli
env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::Sidecar::BrotliExporter
# Zstd
env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::Sidecar::ZstdExporterContributing
Yes please! Open an issue with exporters you want to see added.
Tests
bundle install
bundle exec rakeLicense
The gem is available as open source under the terms of the MIT License.