Asset Pipeline (Sprockets) là framework gom, minify và fingerprint static assets (JS, CSS, images) trước khi deploy.
Vai trò chính:
- Concatenation: gộp nhiều file JS/CSS thành 1 file → giảm HTTP requests.
- Minification: xóa whitespace/comments → file nhỏ hơn.
- Fingerprinting: thêm hash vào tên file (application-abc123.css) → cache busting tự động.
Rails 7+ chuyển sang Propshaft (nhẹ hơn, không gộp file vì HTTP/2 làm điều đó tốt hơn) hoặc import maps + jsbundling-rails. Asset Pipeline vẫn là câu hỏi phổ biến vì nhiều app cũ còn dùng.
The Asset Pipeline (Sprockets) is a framework for concatenating, minifying, and fingerprinting static assets (JS, CSS, images) before deployment.
Main roles:
- Concatenation: merges multiple JS/CSS files into one → fewer HTTP requests.
- Minification: strips whitespace/comments → smaller file size.
- Fingerprinting: appends a hash to filenames (application-abc123.css) → automatic cache busting.
Rails 7+ moves to Propshaft (lighter, no bundling since HTTP/2 handles multiplexing better) or import maps + jsbundling-rails. The Asset Pipeline is still a common interview topic because many legacy apps still use it.