src/content/docs/linter/rules/use-google-font-preconnect.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/performance/useGoogleFontPreconnect`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - This rule belongs to the following domains: - [`next`](/linter/domains#next) - Sources: - Same as [`@next/next/google-font-preconnect`](https://nextjs.org/docs/messages/google-font-preconnect){
"linter": {
"rules": {
"performance": {
"useGoogleFontPreconnect": "error"
}
}
}
}
Ensure the preconnect attribute is used when using Google Fonts.
When using Google Fonts, adding the rel="preconnect" attribute to the <link> tag
that points to https://fonts.gstatic.com is recommended to initiate an early
connection to the font's origin. This improves page load performance by reducing latency.
Failing to use preconnect may result in slower font loading times, affecting user experience.
Note: Next.js automatically adds this preconnect link starting from version 12.0.1, but in cases
where it's manually added, this rule ensures the preconnect attribute is properly used.
<link href="https://fonts.gstatic.com"/>
<link rel="preload" href="https://fonts.gstatic.com"/>
<link rel="preconnect" href="https://fonts.gstatic.com"/>
<link href="/logo.svg" rel="icon" />