By default, Blitz.js will automatically inline font CSS at build time, eliminating an extra round trip to fetch font declarations. This results in improvements to First Contentful Paint (FCP) and Largest Contentful Paint (LCP).
For example:
// Before
<link
href="https://fonts.googleapis.com/css2?family=Inter"
rel="stylesheet"
/>
// After
<style data-href="https://fonts.googleapis.com/css2?family=Inter">
@font-face{font-family:'Inter';font-style:normal...
</style>
To add a web font to your Blitz.js application, use <Head>
. You can add
a font to a specific page like this:
// pages/index.js
import { Head } from "blitz"
export default function IndexPage() {
return (
<div>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Inter"
rel="stylesheet"
/>
</Head>
<p>Hello world!</p>
</div>
)
}
or to your entire application with a
Custom Document
.
// pages/_document.js
import { Document, Html, DocumentHead, Main, BlitzScript } from "blitz"
class MyDocument extends Document {
render() {
return (
<Html>
<DocumentHead>
<link
href="https://fonts.googleapis.com/css2?family=Inter"
rel="stylesheet"
/>
</DocumentHead>
<body>
<Main />
<BlitzScript />
</body>
</Html>
)
}
}
export default MyDocument
Automatic Webfont Optimization currently supports Google Fonts and Typekit
with support for other font providers coming soon. We're also planning to
add control
over loading strategies and font-display
 values.
If you do not want Blitz.js to optimize your fonts, you can opt-out.
// blitz.config.js
module.exports = {
optimizeFonts: false,
}