Performance: Import maps (Rails 7+)
Import maps affect page load speed by controlling how JavaScript modules are loaded and resolved in the browser without bundling.
importmap pin "example", to: "example.js" // Browser loads modules on demand using import maps without bundling
import { example } from './example.js'; // Using a traditional bundler that creates a large single bundle loaded on page start
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Bundled JavaScript | Minimal DOM impact | 0-1 reflows | High paint cost due to blocking scripts | [X] Bad |
| Import maps with on-demand modules | Minimal DOM impact | 0 reflows | Lower paint cost, scripts load asynchronously | [OK] Good |
importmap in Rails 7+?chart.js using importmap in Rails?bin/importmap pin [module].add, C uses invalid rails importmap pin, and D misses the bin/ prefix.<%= javascript_importmap_tags %>
javascript_importmap_tags inserts script tags to load all pinned JS modules via import maps in the HTML.rails importmap pin my_module but your JavaScript module does not load in the browser. What is the most likely mistake?javascript_importmap_tags must be in the layout to load scripts.pin instead of add command is incorrect because pin is the right command. You need to restart the Rails server after pinning is unnecessary; no restart needed. You must compile assets with webpack first is wrong because import maps do not require webpack.config/importmap.rb?pin 'name', to: 'URL' in config/importmap.rb.from and url which are invalid.Pass the test and this pattern moves unknown