Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ export function addToHTMLProxyTransformResult(
// - `shortcut` : only valid for IE <9, use `icon`
// - `mask-icon` : deprecated since Safari 12 (for pinned tabs)
// - `apple-touch-icon-precomposed` : only valid for iOS <7 (for avoiding gloss effect)
// `modulepreload` is also listed because a `data:` URL is fetched as a separate
// module from the emitted chunk, so inlining defeats the preload entirely.
Comment thread
bluwy marked this conversation as resolved.
Outdated
const noInlineLinkRels = new Set([
'icon',
'apple-touch-icon',
'apple-touch-startup-image',
'manifest',
'modulepreload',
])

export const isAsyncScriptMap: WeakMap<
Expand Down
10 changes: 10 additions & 0 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ describe('css url() references', () => {
expect(await getBg('.css-url-quotes-base64-inline')).toMatch(match)
})

test('no base64 inline for modulepreload links', async () => {
const el = await page.$(`link[rel="modulepreload"]`)
const href = await el.getAttribute('href')
expect(href).toMatch(
isBundled
? /\/foo\/bar\/assets\/preload-module-[-\w]{8}\.js/
: 'preload-module.js',
)
})

test('no base64 inline for icon and manifest links', async () => {
const iconEl = await page.$(`link.ico`)
const href = await iconEl.getAttribute('href')
Expand Down
1 change: 1 addition & 0 deletions playground/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<link class="ico" rel="icon" type="image/svg+xml" href="favicon.ico" />
<link rel="manifest" href="manifest.json" />
<link rel="modulepreload" href="preload-module.js" />
<meta
class="meta-og-image"
property="og:image"
Expand Down
2 changes: 2 additions & 0 deletions playground/assets/preload-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// referenced via <link rel="modulepreload">, small enough to hit assetsInlineLimit
export const preloadedModule = 'preloaded'
Loading