feat: smart image preloading with build-time extraction and runtime scheduling #2459
+207
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
image/backgroundImage/background, markdown, Vue componentsrc/imageprops, CSSurl(...)) and store inimages[]onSlideInfoBase- this field survives build-mode content stripping since it's not in the explicit strip list<link rel="preload" as="image">tags in HTML head at build time for all extracted imagesusePreloadImages) with navigation-aware scheduling: immediately preloads current + prev + next + configurable look-ahead window, then all remaining slides after 3sMotivation
Slidev preloads slide components (JS) but not the images inside them. When navigating to a slide with background/embedded images, there's a visible loading flash. PR #2450 addresses this only for
image:frontmatter. This PR provides comprehensive coverage of all image sources with both build-time and runtime preloading.Config API
Files Changed (9 files, ~130 lines added)
packages/types/src/types.tsimages?: string[]toSlideInfoBasepackages/types/src/frontmatter.tspreloadImagestoHeadmatterConfigpackages/parser/src/config.tspreloadImages: truepackages/parser/src/core.tsextractImages()function + integration inparseSlide()packages/slidev/node/setups/indexHtml.tscollectPreloadImages()for<link rel="preload">tagspackages/client/composables/usePreloadImages.tspackages/client/internals/SlidesShow.vueusePreloadImages()alongside component preloadingpackages/client/constants.tspreloadImagestoHEADMATTER_FIELDSpackages/vscode/schema/headmatter.jsonComparison with #2450
image:<Background>,<Image>, etc.)url(...)<link rel="preload">tagsDesign Decisions
data:URIs and Vue template expressions filtered — prevents invalid preload targetsbackgroundfrontmatter filtered by image extension — CSS values likelinear-gradient(...)are not preloadedwatchEffect+ 3s timeout pattern used for component preloading inSlidesShow.vueTest Plan
<link rel="preload" as="image">tags present in HTML headimages[]field exists onmeta.slide(content stripped but images preserved)preloadImages: falsedisables both build-time and runtime preloadingCloses #2450