Sub topic 11
Self-hosting fonts and privacy trade-offs
This chapter assumes you can write an @font-face rule, know what font-display does, and have used the browser's Network panel. It covers what changes when you serve font files from your own domain instead of a font service, and what you gain and lose.
What self-hosting means
Self-hosting means the font files live on your own server or CDN. The page's CSS points at those files, and the browser never contacts a third-party font host.
With the Google Fonts <link> tag, the browser makes two requests to Google hosts. It fetches a stylesheet from fonts.googleapis.com, then the font files from fonts.gstatic.com. Each request sends the visitor's IP address and standard headers to Google. With self-hosting, those requests go to your own origin.
Self-hosting is only possible for fonts whose license allows redistribution. Google Fonts families are openly licensed (mostly the SIL Open Font License), so you can download and serve them. Adobe Fonts are licensed for use through Adobe's service and cannot be downloaded and hosted yourself. For Adobe Fonts, the web project stylesheet is the only supported route.
Why people self-host
- Privacy. No visitor data goes to a font provider. This matters for sites that must limit third-party data sharing. Some European courts and data protection authorities have treated loading Google Fonts from Google's servers as a transfer of personal data (the IP address) without consent. Ask your legal or privacy contact for your own situation. This chapter is not legal advice.
- Performance. The browser reuses the connection it already has to your origin. It skips the extra DNS lookups, connections, and the stylesheet round trip. Since cache partitioning, browsers no longer share cached fonts between sites, so the old argument that visitors already have Inter cached from another site no longer holds.
- Control. You choose the file format, subsets, cache headers, and
font-displayvalue. The font version also stays fixed until you change it.
What you take on
- You must download the files and keep them updated.
- You must set cache headers, such as a long
Cache-Controlwithimmutable, on versioned file names. - You lose Google's per-browser optimization. Google's CSS serves different subsets and formats depending on the browser. With self-hosting you pick them yourself.
- Your server or CDN must handle the traffic.
A self-hosted `@font-face` rule
This rule serves a WOFF2 file from your domain. WOFF2 is supported by all current browsers, so you rarely need other formats.
@font-face {
font-family: "Inter";
src: url("/fonts/inter-regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}Add one rule for each weight and style you use. For a variable font, declare a weight range in a single rule:
@font-face {
font-family: "Inter";
src: url("/fonts/inter-variable.woff2") format("woff2");
font-weight: 100 900;
font-style: normal;
font-display: swap;
}Then preload the most important file so the browser starts the download early:
<link rel="preload" href="/fonts/inter-regular.woff2" as="font" type="font/woff2" crossorigin>The crossorigin attribute is required even for same-origin font files. Without it, the browser fetches the font twice.
Subsetting
A font file contains many glyphs. If your site uses only Latin text, a Latin subset is much smaller than the full file. Tools such as pyftsubset from fonttools can create one. Use unicode-range in @font-face when you split a font into several subsets, so the browser downloads only the pieces a page needs.
Comparing the options
| Aspect | Google Fonts link | Self-hosted open font | Adobe Fonts project |
|---|---|---|---|
| Third-party requests | Yes, to Google | None | Yes, to Adobe |
| Can you host the files? | Optional | Yes | No |
| Update work | None | You do it | None |
| Format and subsets | Chosen by the service | You choose | Chosen by the service |
Common errors
- Font does not load. Check the Network panel for a 404 on the font path. Paths in
url()are relative to the CSS file, not the HTML page. - Fonts load twice. A preload without
crossorigincauses this. - Wrong weight rendered. The
font-weightin@font-facemust match the file. If it does not, the browser may synthesize a faux bold. - Blocked by CORS. If fonts come from a CDN on another origin, that CDN must send an
Access-Control-Allow-Originheader.
Exercise
Your client's privacy policy forbids sending visitor IP addresses to third parties. The design uses Inter from Google Fonts and Proxima Nova from Adobe Fonts. What can you do for each font?
Show answer
Inter is openly licensed, so download the WOFF2 files, serve them from your own domain with @font-face rules, and preload the key file with the crossorigin attribute. Proxima Nova cannot be self-hosted under the Adobe Fonts license, and loading it contacts Adobe. You must either replace it with an openly licensed font of similar style or get a separately licensed font whose license permits self-hosting.