Replies: 4 comments 2 replies
-
|
Beta Was this translation helpful? Give feedback.
-
SummaryAstro has complete information about the module graph of client-side scripts. This can be leveraged to add Exampleexport default defineConfig({
preload: {
modules: true
}
})Goals
Non-goals
Unresolved questions
Related |
Beta Was this translation helpful? Give feedback.
-
|
This seems like an important feature. The PR seems to not have been merged and the bot comment on it doesn't make sense to me. Any update on this? |
Beta Was this translation helpful? Give feedback.
-
|
I spent some 25 to 28 bucks USD on a back-and-forth with Claude Opus 4.6 to come up with a hack that does this via Astro integration. Agent-tested thoroughly and self-tested in clean non-cached server deployments to work reliably. If it helps you, leave an upvote. Thanks. 🙂 Note that this walks the tree for dynamic imports as well, which is probably what you want anyway. (No harm preloading them.) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
Extend the existing
client:options, to add aclient:preloadoption for any astro island tags. Doing so would make it automatically inject<link ref="modulepreload" src="path/to/component.hash.js">right before the</head>in the markup.That, or could adjust the
client:loadbehavior to do this automatically.Background & Motivation
We are wanting to add
rel=modulepreloadlinks to the head section. This lets the browser start downloading JS in the background while the rest of the page is still loading. The problem is that the component JS files have a hash added to the filename, and we want to keep that turned on for the cache-busting reasons.There is a work-around, you can scan the dist folder at run time, find the file that matches
expected.*.js, and use that for the filename. But this is a lot of extra work, it would be ideal if this ability was baked in to astro.Goals
Example
Beta Was this translation helpful? Give feedback.
All reactions