fresh
fresh copied to clipboard
Importing modules using import maps in the client
Is it supported to use <script type="importmap"> within a
I always get An import map is added after module script load was triggered. in the browser console while running in dev mode. Import maps seem to expect to be loaded before everything else on the page and fresh_dev_client.js is always the very first script being loaded.
<script
type="importmap"
dangerouslySetInnerHTML={{
__html: '{ "imports": { "a": "/a.js"} }',
}}
/>
<script
type="module"
dangerouslySetInnerHTML={{
__html: `
import { a } from "a";
`,
}}
/>
This is resolved in Fresh 2 as we don't load any scripts in <head> by default but at the end at </body> instead. This allows you to add an import map earlier.