You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Vite with both, independent React and Svelte project, and the default HTML template (index.html) as an entry-point. The project import web-components from an URL through a script tag in the template.
The web component is served from a different origin than the actual project. The preload tags inserted in the build-process are relative to the project's base and don't respect external origins.
While this is clearly a bug, I want to repeat concerns expressed in other issues (#3133, #5120). I think that automatic insertion of preload can work for smaller projects. However, for bigger projects finding the optimal caching strategy is far more complex and preloading all resources can have a negative impact on performance. In my particular case, I wasn't able to prevent the preloading using optimizeDeps.exclude. Using library mode to prevent preloading is no viable option. It would really help to have an independent setting to disable preloading altogether.
<!-- single header chunks omitted for brevity --><linkrel="modulepreload" as="script" crossorigin="" href="assets/header.mjs">
Note: Not only does it use a relative path, it also uses the incorrect path!
Console Output:
header.mjs:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
I have tried to write a Vite transformer plugin, but it did have no influence on preload tags. I think this is a clear bug and should be resolved by the Vite developers.
We have identified the problem. The imported web component had no base defined, while the importing project uses a relative base. The imported component now uses an absolute URL as base, which fixes the preloads in the importing project.
Describe the bug
I'm using Vite with both, independent React and Svelte project, and the default HTML template (
index.html
) as an entry-point. The project import web-components from an URL through a script tag in the template.The web component is served from a different origin than the actual project. The preload tags inserted in the build-process are relative to the project's base and don't respect external origins.
While this is clearly a bug, I want to repeat concerns expressed in other issues (#3133, #5120). I think that automatic insertion of preload can work for smaller projects. However, for bigger projects finding the optimal caching strategy is far more complex and preloading all resources can have a negative impact on performance. In my particular case, I wasn't able to prevent the preloading using
optimizeDeps.exclude
. Using library mode to prevent preloading is no viable option. It would really help to have an independent setting to disable preloading altogether.Reproduction
Config:
HTML Output:
Note: Not only does it use a relative path, it also uses the incorrect path!
Console Output:
The expected preload tag would be
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: