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
+27-77Lines changed: 27 additions & 77 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,85 +138,41 @@ Unpinning and removing "react"
138
138
139
139
## Subresource Integrity (SRI)
140
140
141
-
For enhanced security, importmap-rails automatically includes [Subresource Integrity (SRI)](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) hashes by default when pinning packages. This ensures that JavaScript files loaded from CDNs haven't been tampered with.
142
-
143
-
### Default behavior with integrity
144
-
145
-
When you pin a package, integrity hashes are automatically included:
146
-
147
-
```bash
148
-
./bin/importmap pin lodash
149
-
Pinning "lodash" to vendor/javascript/lodash.js via download from https://ga.jspm.io/npm:[email protected]/lodash.js
150
-
Using integrity: sha384-PkIkha4kVPRlGtFantHjuv+Y9mRefUHpLFQbgOYUjzy247kvi16kLR7wWnsAmqZF
151
-
```
152
-
153
-
This generates a pin in your `config/importmap.rb` with the integrity hash:
If you need to disable integrity checking (not recommended for security reasons), you can use the `--no-integrity` flag:
162
-
163
-
```bash
164
-
./bin/importmap pin lodash --no-integrity
165
-
Pinning "lodash" to vendor/javascript/lodash.js via download from https://ga.jspm.io/npm:[email protected]/lodash.js
166
-
```
167
-
168
-
This generates a pin without integrity:
169
-
170
-
```ruby
171
-
pin "lodash"# @4.17.21
172
-
```
173
-
174
-
### Adding integrity to existing pins
175
-
176
-
If you have existing pins without integrity hashes, you can add them using the `integrity` command:
177
-
178
-
```bash
179
-
# Add integrity to specific packages
180
-
./bin/importmap integrity lodash react
181
-
182
-
# Add integrity to all pinned packages
183
-
./bin/importmap integrity
184
-
185
-
# Update your importmap.rb file with integrity hashes
186
-
./bin/importmap integrity --update
187
-
```
141
+
For enhanced security, importmap-rails supports [Subresource Integrity (SRI)](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) hashes for packages loaded from external CDNs.
188
142
189
143
### Automatic integrity for local assets
190
144
191
-
For local assets served by the Rails asset pipeline (like those created with `pin` or `pin_all_from`), you can use `integrity: true` to automatically calculate integrity hashes from the compiled assets:
145
+
Starting with importmap-rails, **`integrity: true` is the default** for all pins. This automatically calculates integrity hashes for local assets served by the Rails asset pipeline:
192
146
193
147
```ruby
194
148
# config/importmap.rb
195
149
196
-
# Automatically calculate integrity from asset pipeline
Modern browsers will automatically validate these integrity hashes when loading the JavaScript modules, ensuring the files haven't been modified.
257
219
258
-
### Redownloading packages with integrity
259
-
260
-
The `pristine` command also includes integrity by default:
261
-
262
-
```bash
263
-
# Redownload all packages with integrity (default)
264
-
./bin/importmap pristine
265
-
266
-
# Redownload packages without integrity
267
-
./bin/importmap pristine --no-integrity
268
-
```
269
-
270
220
## Preloading pinned modules
271
221
272
222
To avoid the waterfall effect where the browser has to load one file after another before it can get to the deepest nested import, importmap-rails uses [modulepreload links](https://developers.google.com/web/updates/2017/12/modulepreload) by default. If you don't want to preload a dependency, because you want to load it on-demand for efficiency, append `preload: false` to the pin.
0 commit comments