Replies: 2 comments 1 reply
-
If it's okay, please let me contribute to the implementation 👍 |
Beta Was this translation helpful? Give feedback.
1 reply
-
very good! It does solve the problem. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Related: #6773 (Referenced implementation)
PoC: #15373
for Production: #16552
Summary
Solving the Cascading Cache Invalidation Problem using importmap.
Basic Example
Rewrite import paths and embed importmap in HTML.
to
Even if the content hash of the module changes, the cache for main.js won't be invalidated 👍
Motivation
Modern tools, including Vite, are having the Cascading Cache Invalidation Problem. Among the solutions, using importmap is the simplest and most powerful. With the release of Safari 16.4 in March 2023, importmap became available in major browsers. Some libraries are also looking to solve this problem.
Detailed Design
The process involves editing imports during
renderChunk
step and writing the importmap viabuildHtmlPlugin
hook.Why not implement it as a plugin?
1. Approach of analyzing and rewriting assets after build process
2. Approach of concluding within the build process
renderChunk
and to delete them in thegenerateBundle
step. It's necessary to consider the difference between the keys of the bundle list and the hash included in the file name written inside the import during this process (cssPostPlugin).Why new hashes are added instead of removing them?
assets/*.js
, so there's a possibility that the keys of importmap might duplicate.?worker
or?raw
for a single file, the file name remains the same, so there's a possibility that the keys of the importmap might duplicate. Identifiable values likefacadeModuleId
should be used.Drawbacks
In cases like with VitePress, where the outputs are directly imported using Node.js, importmap cannot be used, or an implementation considering importmap becomes necessary.
Alternatives
Adoption Strategy
Does not require migrations from plugin authors.
Unresolved Questions
Legacy support seems feasible with systemjs-importmap. Under investigation.done 👍 22f8d74Beta Was this translation helpful? Give feedback.
All reactions