Skip to content

Commit f7a4ed1

Browse files
feat: disable font preloading option in qwikVite (#7297)
1 parent 915e7bb commit f7a4ed1

File tree

1 file changed

+11
-1
lines changed
  • packages/qwik/src/optimizer/src/plugins

1 file changed

+11
-1
lines changed

packages/qwik/src/optimizer/src/plugins/vite.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
6969
const fileFilter: QwikVitePluginOptions['fileFilter'] = qwikViteOpts.fileFilter
7070
? (id, type) => TRANSFORM_REGEX.test(id) || qwikViteOpts.fileFilter!(id, type)
7171
: () => true;
72+
const disableFontPreload = qwikViteOpts.disableFontPreload ?? false;
7273
const injections: GlobalInjections[] = [];
7374
const qwikPlugin = createQwikPlugin(qwikViteOpts.optimizerOptions);
7475

@@ -523,7 +524,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
523524
}
524525
} else {
525526
const selectedFont = FONTS.find((ext) => fileName.endsWith(ext));
526-
if (selectedFont) {
527+
if (selectedFont && !disableFontPreload) {
527528
injections.unshift({
528529
tag: 'link',
529530
location: 'head',
@@ -930,6 +931,15 @@ interface QwikVitePluginCommonOptions {
930931
* to be stable between releases
931932
*/
932933
experimental?: (keyof typeof ExperimentalFeatures)[];
934+
935+
/**
936+
* Disables automatic preloading of font assets (WOFF/WOFF2/TTF) found in the build output. When
937+
* enabled, the plugin will not add `<link rel="preload">` tags for font files in the document
938+
* head.
939+
*
940+
* Disabling may impact Cumulative Layout Shift (CLS) metrics.
941+
*/
942+
disableFontPreload?: boolean;
933943
}
934944

935945
interface QwikVitePluginCSROptions extends QwikVitePluginCommonOptions {

0 commit comments

Comments
 (0)