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
means "everytime you see `import React from "react"`
57
+
means "everytime you see `import React from "react"`
58
58
change it to `import React from "https://ga.jspm.io/npm:[email protected]/index.js"`"
59
59
60
60
```js
61
-
importReactfrom"react"
61
+
importReactfrom"react"
62
62
// => import React from "https://ga.jspm.io/npm:[email protected]/index.js"
63
63
```
64
64
@@ -131,6 +131,91 @@ If you later wish to remove a downloaded pin:
131
131
Unpinning and removing "react"
132
132
```
133
133
134
+
## Subresource Integrity (SRI)
135
+
136
+
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.
137
+
138
+
### Default behavior with integrity
139
+
140
+
When you pin a package, integrity hashes are automatically included:
141
+
142
+
```bash
143
+
./bin/importmap pin lodash
144
+
Pinning "lodash" to vendor/javascript/lodash.js via download from https://ga.jspm.io/npm:[email protected]/lodash.js
145
+
Using integrity: sha384-PkIkha4kVPRlGtFantHjuv+Y9mRefUHpLFQbgOYUjzy247kvi16kLR7wWnsAmqZF
146
+
```
147
+
148
+
This generates a pin in your `config/importmap.rb` with the integrity hash:
Modern browsers will automatically validate these integrity hashes when loading the JavaScript modules, ensuring the files haven't been modified.
206
+
207
+
### Redownloading packages with integrity
208
+
209
+
The `pristine` command also includes integrity by default:
210
+
211
+
```bash
212
+
# Redownload all packages with integrity (default)
213
+
./bin/importmap pristine
214
+
215
+
# Redownload packages without integrity
216
+
./bin/importmap pristine --no-integrity
217
+
```
218
+
134
219
## Preloading pinned modules
135
220
136
221
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