From 0cb84d65e3f1d804a4fbf91d7650d81ef90ee8cc Mon Sep 17 00:00:00 2001 From: thejackshelton Date: Wed, 29 Jan 2025 10:26:41 -0600 Subject: [PATCH] feat: disable font preloading option in qwikVite --- packages/qwik/src/optimizer/src/plugins/vite.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/qwik/src/optimizer/src/plugins/vite.ts b/packages/qwik/src/optimizer/src/plugins/vite.ts index 158188f6836..9f51cfd5094 100644 --- a/packages/qwik/src/optimizer/src/plugins/vite.ts +++ b/packages/qwik/src/optimizer/src/plugins/vite.ts @@ -73,6 +73,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any { const fileFilter: QwikVitePluginOptions['fileFilter'] = qwikViteOpts.fileFilter ? (id, type) => TRANSFORM_REGEX.test(id) || qwikViteOpts.fileFilter!(id, type) : () => true; + const disableFontPreload = qwikViteOpts.disableFontPreload ?? false; const injections: GlobalInjections[] = []; const qwikPlugin = createPlugin(qwikViteOpts.optimizerOptions); @@ -549,7 +550,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any { } } else { const selectedFont = FONTS.find((ext) => fileName.endsWith(ext)); - if (selectedFont) { + if (selectedFont && !disableFontPreload) { injections.unshift({ tag: 'link', location: 'head', @@ -1000,6 +1001,15 @@ interface QwikVitePluginCommonOptions { * to be stable between releases */ experimental?: (keyof typeof ExperimentalFeatures)[]; + + /** + * Disables automatic preloading of font assets (WOFF/WOFF2/TTF) found in the build output. When + * enabled, the plugin will not add `` tags for font files in the document + * head. + * + * Disabling may impact Cumulative Layout Shift (CLS) metrics. + */ + disableFontPreload?: boolean; } interface QwikVitePluginCSROptions extends QwikVitePluginCommonOptions {