Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chunk importmap #16552

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: chunk importmap #16552

wants to merge 1 commit into from

Conversation

bhbs
Copy link
Contributor

@bhbs bhbs commented Apr 29, 2024

It seems that many people have been wanting improvements in chunk cache efficiency, so I've created this PR. If you could, please take a look and review this! Thank you Vite team!!

Description

Fixes: #6773 
Related: #15372
Related: #15373

Creating an importmap for chunks helps prevent cascading cache invalidation. This importmap features a list of filenames with file ID-based hashes linked to filenames with content-based hashes. When one chunk references another, it uses the ID-hashed filename instead of the content-hashed filename. As a result, only the updated chunk requires cache invalidation in the browser, leaving intermediary chunks unchanged. This strategy enhances the cache hit rate following deployments.

Implementation

During the renderChunk step, file hash placeholders in the code are overwritten with stable ID hashes. This process maintains a record of the hash placeholders and their corresponding ID hashes. (After that, during the augmentHash step, filenames are assigned based on the content.)

Based on the generated chunk list and the record of hash placeholders and their corresponding hashes, an importmap is generated and inserted into the HTML.

image

Others

  • An importmap is generated for legacy bundles using the same method, but a systemjs-importmap is inserted instead of a standard importmap.
  • Consider the importmap during the CSS processing (cssPostPlugin).
  • Consider the importmap during import analysis (buildImportAnalysisPlugin).
  • Only one importmap can be loaded at a time (MDN). If an importmap already exists, it needs to be merged (buildHtmlPlugin).

Copy link

stackblitz bot commented Apr 29, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bhbs bhbs marked this pull request as ready for review April 29, 2024 06:59
@bhbs bhbs mentioned this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[build] importing from hashed chunks makes caching terribly ineffective
1 participant