You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-2Lines changed: 48 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ With Rails 8, Propshaft is the default asset pipeline for new applications. With
16
16
17
17
## Usage
18
18
19
-
Propshaft makes all the assets from all the paths it's been configured with through `config.assets.paths` available for serving and will copy all of them into `public/assets` when precompiling. This is unlike Sprockets, which did not copy over assets that hadn't been explicitly included in one of the bundled assets.
19
+
Propshaft makes all the assets from all the paths it's been configured with through `config.assets.paths` available for serving and will copy all of them into `public/assets` when precompiling. This is unlike Sprockets, which did not copy over assets that hadn't been explicitly included in one of the bundled assets.
20
20
21
21
You can however exempt directories that have been added through the `config.assets.excluded_paths`. This is useful if you're for example using `app/assets/stylesheets` exclusively as a set of inputs to a compiler like Dart Sass for Rails, and you don't want these input files to be part of the load path. (Remember you need to add full paths, like `Rails.root.join("app/assets/stylesheets")`).
22
22
@@ -50,9 +50,55 @@ export default class extends Controller {
50
50
51
51
If you need to put multiple files that refer to each other through Propshaft, like a JavaScript file and its source map, you have to digest these files in advance to retain stable file names. Propshaft looks for the specific pattern of `-[digest].digested.js` as the postfix to any asset file as an indication that the file has already been digested.
52
52
53
+
## Subresource Integrity (SRI)
54
+
55
+
Propshaft supports Subresource Integrity (SRI) to help protect against malicious modifications of assets. SRI allows browsers to verify that resources fetched from CDNs or other sources haven't been tampered with by checking cryptographic hashes.
56
+
57
+
### Enabling SRI
58
+
59
+
To enable SRI support, configure the hash algorithm in your Rails application:
60
+
61
+
```ruby
62
+
config.assets.integrity_hash_algorithm ="sha384"
63
+
```
64
+
65
+
Valid hash algorithms include:
66
+
-`"sha256"` - SHA-256 (most common)
67
+
-`"sha384"` - SHA-384 (recommended for enhanced security)
68
+
-`"sha512"` - SHA-512 (strongest)
69
+
70
+
### Using SRI in your views
71
+
72
+
Once configured, you can enable SRI by passing the `integrity: true` option to asset helpers:
**Important**: SRI only works in secure contexts (HTTPS) or during local development. The integrity hashes are automatically omitted when serving over HTTP in production for security reasons.
89
+
90
+
### Bulk stylesheet inclusion with SRI
91
+
92
+
Propshaft extends `stylesheet_link_tag` with special symbols for bulk inclusion:
93
+
94
+
```erb
95
+
<%= stylesheet_link_tag :all, integrity: true %> <!-- All stylesheets -->
Before every request Propshaft checks if any asset was updated to decide if a cache sweep is needed. This verification is done using the application's configured file watcher which, by default, is `ActiveSupport::FileUpdateChecker`.
101
+
Before every request Propshaft checks if any asset was updated to decide if a cache sweep is needed. This verification is done using the application's configured file watcher which, by default, is `ActiveSupport::FileUpdateChecker`.
56
102
57
103
If you have a lot of assets in your project, you can improve performance by adding the `listen` gem to the development group in your Gemfile, and this line to the `development.rb` environment file:
0 commit comments