When working with asset pipelines in Ruby on Rails 7 and 8, you might encounter Sprockets and Propshaft—two asset handling libraries. While both aim to serve static assets like JavaScript, CSS, images, and fonts, they do so in different ways.
This post will walk you through what each does, how they differ, and when you might want to use one over the other.
📦 What is Sprockets?
Sprockets is the original Rails asset pipeline system, introduced way back in Rails 3.1. It allows developers to:
- Concatenate and minify JavaScript and CSS
- Preprocess assets using things like SCSS, CoffeeScript, ERB, etc.
- Fingerprint assets for cache busting
- Compile assets at deploy time
It works well for traditional Rails applications where the frontend and backend are tightly coupled.
Pros:
- Mature and stable
- Rich preprocessing pipeline (SCSS, CoffeeScript, ERB, etc.)
- Supports advanced directives like
//= require_tree .
Cons:
- Complex internal logic
- Slower compilation times
- Relies on a manifest file that can get messy
- Tightly coupled with older Rails asset practices
🧵 What is Propshaft?
Propshaft is the newer asset pipeline introduced by the Rails team as an alternative to Sprockets. It focuses on simplicity and modern best practices. Propshaft was added as an optional asset pipeline starting in Rails 7 and is included by default in some new apps.
Design Philosophy:
Propshaft aims to work like a static file server with fingerprinting and logical path mapping, rather than a full asset compiler.
Key Features:
- Uses logical paths (e.g.,
/assets/application.css) - No preprocessing pipeline by default (but supports it via extensions like Tailwind or Sass)
- Supports digesting (fingerprinting) of assets
- Leaner and faster than Sprockets
- Easier to integrate with modern JavaScript bundlers (like importmaps, esbuild, or webpack)
Pros:
- Lightweight and fast
- Easier to debug
- Works great with importmaps and Hotwire
- Modern, forward-looking approach
Cons:
- No advanced preprocessing by default
- Limited plugin ecosystem (still maturing)
- Doesn’t support old Sprockets directives
🔍 Key Differences at a Glance
| Feature | Sprockets | Propshaft |
|---|---|---|
| Introduced In | Rails 3.1 | Rails 7 |
| Default in Rails | Rails 6 and earlier | Optional from Rails 7+ |
| Preprocessing Support | Yes (SCSS, ERB, CoffeeScript, etc.) | No (only raw assets by default) |
| Speed | Slower | Faster |
| Configuration Complexity | Higher | Minimal |
| Plugin Ecosystem | Large and mature | New and growing |
| Use With Importmaps/Hotwire | Can work, but heavier | Ideal |
| Debugging | Harder due to complexity | Easier |
🧰 When Should You Use Sprockets?
Choose Sprockets if:
- You are upgrading a legacy Rails app
- Your project already relies on Sprockets
- You use heavy asset preprocessing
- You need compatibility with gems that depend on Sprockets
⚡ When Should You Use Propshaft?
Choose Propshaft if:
- You are starting a new Rails 7/8 project
- You use Importmaps or Hotwire/Turbo
- You prefer faster and simpler asset handling
- You don’t need complex preprocessing
Propshaft pairs particularly well with modern frontend workflows like Tailwind CSS (via build tools) or StimulusJS (with importmaps).
🛠️ Switching from Sprockets to Propshaft
If you’re migrating, here are basic steps:
- Remove
sprockets-railsgem from your Gemfile:# Gemfile # gem "sprockets-rails" - Add
propshaft:gem "propshaft" - Update
config/application.rb:config.assets.resolver = Propshaft::Resolver.new( paths: [Rails.root.join("app/assets")] ) - Remove
app/assets/config/manifest.js(used by Sprockets) - Move all assets to the correct logical paths under
app/assets - Use digested URLs as needed (
asset_path("application.css")etc.)
🧪 Real Example in Rails 8
Here’s how your application.html.erb might look using Propshaft:
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
And your app/assets/builds/application.css could be compiled via Tailwind or SCSS using a toolchain.
🧠 Final Thoughts
Sprockets has served Rails well for over a decade, but Propshaft is the new lightweight future. If you’re starting fresh, Propshaft is a strong choice, especially when used alongside Hotwire, Importmaps, or modern JS bundlers.
However, don’t feel pressured to switch if your current Sprockets setup works fine—Rails continues to support both.
✨ TL;DR
- Sprockets = older, feature-rich, best for legacy apps
- Propshaft = newer, minimal, better for modern workflows
Choose based on your app’s needs and complexity. Cheers! 🚀