I use custom fonts on a website. It works, but it looks like they aren't cached long enough, as I way too often get FOUT. Some times multiple times a day, on production. I'm hoping I can cache fonts for a longer period (or another solution) to prevent this from occurring as often.
Fonts are preloaded in _document.tsx like this:
<link
rel='preload'
as='font'
href='/fonts/Calibre-Regular.woff2'
type='font/woff2'
crossOrigin='anonymous'
/>
Then in _app.tsx like this:
<script jsx>{`
@font-face {
font-family: 'Calibre';
font-display: swap;
src: url('/fonts/Calibre-Regular.woff2') format('woff2'),
url('/fonts/Calibre-Regular.woff') format('woff');
}
`}</script>
How can I improve this? Or set a longer cache time for the fonts?