importmap-rails 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 446689178bd41da319ca7d85a90090d8aaaebcda8ba79fb8216fc42a1948af4b
4
- data.tar.gz: d856a84a0acf723fe91b75ccb4e3f67727a5e1f64bde871a8604a79892cdc79c
3
+ metadata.gz: f7e0d50066c60a35a2490440f039b26f23a34426a5988ad5db9680cf3c436609
4
+ data.tar.gz: 630330c8ba8fa300c385d30449a69e8cf88b229a17f16b599b917a7258522bdb
5
5
  SHA512:
6
- metadata.gz: cf025187c8d441b30e2c2d685c114063ef768132952a42038e94d99d42016af8e094586fe5939840cb42c99b449e91070c1b6666e0ed9d3167123a80a097c51c
7
- data.tar.gz: 1594f8e3c0bb824fbfd33bb04688a101330af87c91ad2bf3df3fd4531f0821d3b2f457e53a63ff03544307e0bd7199e2208718dda712ff50db1a5350535d4f60
6
+ metadata.gz: 17082f8ca98917f7d046f62b4c5ed7efb68e72635025397afacdc5ed3fe5b4e048019e1f34e5348c435a609871b7069ae856731389a99687b8167e53ac16040a
7
+ data.tar.gz: 929d91e9ad8ae8d75201c08c7b72a56ce85d7774ac1eccfb44df9e22eb4dd3e7667626803ce5bd5c6278b20d0b100ad015534afdabc5ac872ed923da8482b010
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [Import maps](https://github.com/WICG/import-maps) let you import JavaScript modules using logical names that map to versioned/digested files – directly from the browser. So you can [build modern JavaScript applications using JavaScript libraries made for ESM without the need for transpiling or bundling](https://world.hey.com/dhh/modern-web-apps-without-javascript-bundling-or-transpiling-a20f2755).This frees you from needing Webpack, Yarn, npm, or any other part of the JavaScript toolchain. All you need is the asset pipeline that's already included in Rails.
4
4
 
5
- With this approach you'll ship many small JavaScript files instead of one big JavaScript file. Thanks to HTTP2 that no longer carries a material performance penalty during the initial transport, and in fact offers substantial benefits over the long run due to better caching dynamics. Whereas before any change to any JavaScript file included in your big bundle would invalidate the cache for the the whole bundle, now only the cache for that single file is invalidated.
5
+ With this approach you'll ship many small JavaScript files instead of one big JavaScript file. Thanks to HTTP/2 that no longer carries a material performance penalty during the initial transport, and in fact offers substantial benefits over the long run due to better caching dynamics. Whereas before any change to any JavaScript file included in your big bundle would invalidate the cache for the the whole bundle, now only the cache for that single file is invalidated.
6
6
 
7
7
  There's [native support for import maps in Chrome/Edge 89+](https://caniuse.com/?search=importmap), and [a shim available](https://github.com/guybedford/es-module-shims) for any browser with basic ESM support. So your app will be able to work with all the evergreen browsers.
8
8
 
@@ -168,11 +168,27 @@ And pinning JavaScript modules from the engine:
168
168
  pin_all_from File.expand_path("../app/assets/javascripts", __dir__)
169
169
  ```
170
170
 
171
+
172
+ ## Include a digest of the import map in your etag
173
+
174
+ If you're using etags generated by Rails helpers like `stale?` or `fresh_when`, you need to include the digest of the import map into this calculation. Otherwise your application will return 302 cache responses even when your JavaScript assets have changed. You can avoid this with something like:
175
+
176
+ ```ruby
177
+ class ApplicationController < ActionController::Base
178
+ etag { Rails.application.config.importmap.digest(resolver: helpers) if request.format&.html? }
179
+ end
180
+ ```
181
+
171
182
  ## Expected errors from using the es-module-shim
172
183
 
173
184
  While import maps are native in Chrome and Edge, they need a shim in other browsers that'll produce a JavaScript console error like `TypeError: Module specifier, 'application' does not start with "/", "./", or "../".`. This error is normal and does not have any user-facing consequences.
174
185
 
175
186
 
187
+ ## Turning off the shim
188
+
189
+ Under certain circumstances, like running system tests using chromedriver under CI (which may be resource constrained and trigger errors in certain cases), you may want to explicitly turn off including the shim. If can do this by calling the bulk tag helper with `javascript_importmap_tags("application", shim: false)`. Thus you can pass in something like `shim: !ENV["CI"]`. If you want, and are sure you're not doing any full-page caching, you can also connect this directive to a user agent check (using a gem like `useragent`) to check whether the browser is chrome/edge 89+. But you really shouldn't have to, as the shim is designed to gracefully work with natively compatible drivers.
190
+
191
+
176
192
  ## License
177
193
 
178
194
  Importmap for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,11 +1,11 @@
1
1
  module Importmap::ImportmapTagsHelper
2
2
  # Setup all script tags needed to use an importmap-powered entrypoint (which defaults to application.js)
3
- def javascript_importmap_tags(entry_point = "application")
3
+ def javascript_importmap_tags(entry_point = "application", shim: true)
4
4
  safe_join [
5
5
  javascript_inline_importmap_tag,
6
6
  javascript_importmap_module_preload_tags,
7
- javascript_importmap_shim_nonce_configuration_tag,
8
- javascript_importmap_shim_tag,
7
+ (javascript_importmap_shim_nonce_configuration_tag if shim),
8
+ (javascript_importmap_shim_tag if shim),
9
9
  javascript_import_module_tag(entry_point)
10
10
  ].compact, "\n"
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Importmap
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: importmap-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson