Skip to content

Commit 3743c1b

Browse files
authored
Update custom.ts
We can not do a prefetch and a preload for the same files.
1 parent 89591a2 commit 3743c1b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/custom.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default (options: CustomFonts, config: ResolvedConfig) => {
164164
display = 'auto',
165165
// eslint-disable-next-line prefer-const
166166
preload = true,
167-
prefetch = true,
167+
prefetch = false,
168168
} = options
169169

170170
// --- Cast as array of `CustomFontFamily`.
@@ -204,8 +204,13 @@ export default (options: CustomFonts, config: ResolvedConfig) => {
204204
.map(src => src.replace(config.root, '.'))
205205

206206
// --- Generate `<link>` tags.
207+
// --- We can not do a prefetch and a preload for the same files.
208+
if(preload && prefetch){
209+
console.warn('vite-plugin-fonts','We can not do a prefetch and a preload for the same files.');
210+
console.warn('vite-plugin-fonts','The prefetch stand for a lower priority for the resource (maybe we will need it in a future page) whereas preload is for the current page, so we can not have both.')
211+
};
207212
if (preload) tags.push(...hrefs.map(createPreloadFontFaceLink))
208-
if (prefetch) tags.push(...hrefs.map(createPrefetchFontFaceLink))
213+
if (prefetch && !preload) tags.push(...hrefs.map(createPrefetchFontFaceLink))
209214

210215
// --- Generate CSS `@font-face` rules.
211216
for (const face of faces) css.push(createFontFaceCSS(face))

0 commit comments

Comments
 (0)