|
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", shim: true) |
| 3 | + def javascript_importmap_tags(entry_point = "application", shim: true, inline_importmap_cache_key: :json, module_preload_tags_cache_key: :preloaded_module_paths) |
4 | 4 | safe_join [
|
5 |
| - javascript_inline_importmap_tag, |
6 |
| - javascript_importmap_module_preload_tags, |
| 5 | + javascript_inline_importmap_tag(Rails.application.importmap.to_json(resolver: self, cache_key: inline_importmap_cache_key)), |
| 6 | + javascript_importmap_module_preload_tags(cache_key: module_preload_tags_cache_key), |
7 | 7 | (javascript_importmap_shim_nonce_configuration_tag if shim),
|
8 | 8 | (javascript_importmap_shim_tag if shim),
|
9 | 9 | javascript_import_module_tag(entry_point)
|
@@ -34,15 +34,15 @@ def javascript_importmap_shim_tag(minimized: true)
|
34 | 34 | # Import a named JavaScript module(s) using a script-module tag.
|
35 | 35 | def javascript_import_module_tag(*module_names)
|
36 | 36 | imports = Array(module_names).collect { |m| %(import "#{m}") }.join("\n")
|
37 |
| - tag.script imports.html_safe, |
| 37 | + tag.script imports.html_safe, |
38 | 38 | type: "module", nonce: request&.content_security_policy_nonce
|
39 | 39 | end
|
40 | 40 |
|
41 | 41 | # Link tags for preloading all modules marked as preload: true in the `importmap`
|
42 | 42 | # (defaults to Rails.application.importmap), such that they'll be fetched
|
43 | 43 | # in advance by browsers supporting this link type (https://caniuse.com/?search=modulepreload).
|
44 |
| - def javascript_importmap_module_preload_tags(importmap = Rails.application.importmap) |
45 |
| - javascript_module_preload_tag(*importmap.preloaded_module_paths(resolver: self)) |
| 44 | + def javascript_importmap_module_preload_tags(importmap = Rails.application.importmap, cache_key: :preloaded_module_paths) |
| 45 | + javascript_module_preload_tag(*importmap.preloaded_module_paths(resolver: self, cache_key: cache_key)) |
46 | 46 | end
|
47 | 47 |
|
48 | 48 | # Link tag(s) for preloading the JavaScript module residing in `*paths`. Will return one link tag per path element.
|
|
0 commit comments