-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Clear and concise description of the problem
This is a bit niche, but ideally when the final bundle would contain no user JavaScript it should omit the script tags in the output.
For a SPA this is never going to happen, but for MPA's it is actually somewhat common to have no JavaScript required for a page. For example, imagine you have a dead simple 404 page without any interactivity besides links. Likely in that case you'll still have styles that need to be output, but no scripts.
Suggested solution
From what I can tell we'd need to make this script only be added conditionally.
To do this we'd need to be able to tell if the output content is empty of user content.
There are two problems with that though:
- Inlined css is still be included in the JS output until it gets minified.
- The
vite/dynamic-import-polyfillis unconditionally loaded.
Roughly I think we'd need update the code to first check if any additional imports we're loaded by the chunk. If not then we'd check if any of the modules are not "empty" (this is where the inline css variables is a problem). Then finally if all modules are empty (perhaps special casing vite/dynamic-import-polyfill) we should be able to safely omit adding this script.
Alternative
If left alone the downside is that the browser unnecessarily downloads a tiny JavaScript file.
Additional context
This is something we'd like to see for our MPA SSR setup using the marko/vite plugin, since it's something all of our other bundler plugins enable.