How to load custom *remote* font with Next.js and Vercel? #56684
Replies: 6 comments
-
I'd also love to learn about this! |
Beta Was this translation helpful? Give feedback.
-
Any update on this? Came across a similar situation. |
Beta Was this translation helpful? Give feedback.
-
Is there really no native way to use fonts you have hosted on your own CDN like Cloudflare R2? Just google and local fonts only? |
Beta Was this translation helpful? Give feedback.
-
+1. Would love to remote fonts supported in next/font. Here’s how I’ve done it in the interim, for any lurkers reading: I’m already using Pigment CSS (like styled-components). Pigment CSS supports and recommends setting a single global CSS instance in the root import { globalCss } from "@pigment-css/react";
globalCss`
@font-face {
font-family: 'National';
src: url('https://mystoragelocation.example/national-2-regular.woff2') format('woff2');
font-weight: 500;
font-style: normal;
font-display: swap;
}
// Repeat above for the other font-weights
// Apply that font family to all elements
* {
font-family: 'National', system-ui, -apple-system, sans-serif;
} It’s not the cleanest solution, and misses out on some next/font niceties (e.g. subsetting), but it works. I subset (subsetted?) the font manually with fonttools and used that as my remote font source: # Install fonttools and brotli
pip install fonttools
pip install brotli
# Loop through all National font files
for font in national-2-*.woff2; do
# Extract the name without extension
basename="${font%.woff2}"
echo "Subsetting $font..."
pyftsubset "$font" \
--output-file="${basename}-subset.woff2" \
--flavor=woff2 \
--layout-features='*' \
--unicodes="U+0000-00FF" \
--desubroutinize
done
echo "Done! Created subset versions of all fonts" |
Beta Was this translation helpful? Give feedback.
-
Yet another upvote. Currently it's challenging to use |
Beta Was this translation helpful? Give feedback.
-
Yet another upvote. Seems like such a basic feature. remoteFont() would solve being able to use the entire Adobe Fonts library in one fell swoop. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I am looking at https://nextjs.org/docs/app/api-reference/components/font and https://nextjs.org/docs/pages/building-your-application/optimizing/fonts but they only show:
What if my font is hosted in an s3 bucket? Or some other remote URL? How can I load it then? I have 10,000 fonts, I think it is too many to load "locally" in a Vercel app, I would prefer to have this many fonts loaded in a dedicated CDN. Something like this would be great:
Or even:
Thanks for your help!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions