Sub topic 11
Self-hosting fonts and privacy trade-offs
This chapter covers serving font files from your own domain instead of from Google or Adobe. It assumes you can write a <link> element, a CSS rule, and read the Network panel in browser developer tools. It also assumes you have read the earlier chapters on embedding Google Fonts and Adobe Fonts, and on font-display.
What self-hosting means
When you embed Google Fonts with a <link> tag, the visitor's browser makes requests to fonts.googleapis.com for a stylesheet and to fonts.gstatic.com for the font files. Adobe Fonts works the same way through use.typekit.net. These are third-party requests. The browser sends them to servers you do not control.
Self-hosting means you download the font files, put them on your own server or CDN, and describe them with your own @font-face rules. The browser then fetches everything from your domain.
Which fonts you may self-host
Licensing decides whether self-hosting is an option at all.
| Service | Can you download and self-host? | Notes |
|---|---|---|
| Google Fonts | Yes, for most of the catalog | Families are published under open licenses such as the SIL Open Font License. Check the license of the specific family. |
| Adobe Fonts | No | Fonts are licensed to you through a subscription and are delivered only through the service's web projects. |
Adobe Fonts is the more restrictive case. Its web projects exist so that Adobe can serve the fonts and enforce the license. If you stop your subscription or remove the font from your project, the stylesheet stops delivering it. You cannot copy those files to your own server. If you need to self-host a commercial typeface, buy a web license from the foundry or a reseller that explicitly permits it.
Before downloading any font, open its license and confirm that web embedding and redistribution on your own server are allowed. For Google Fonts families this is almost always true, but it is a per-family fact, not a platform guarantee.
Getting the files
For a Google Fonts family you have two common routes.
- Download the family from its Google Fonts page, then convert or subset the files yourself.
- Use a community tool that fetches the WOFF2 files and generates the CSS for you. Several exist, and some ship fonts as npm packages.
Whichever route you choose, aim for WOFF2. It is a compressed font format supported by all current browsers, and it is much smaller than TTF or OTF files. A WOFF2 file is usually all you need. Serving older formats as well adds maintenance cost for browsers that almost nobody uses now.
If a family supports many languages, the full file can be large. You can reduce it by subsetting, which means keeping only the characters you use, such as Latin. Google's hosted CSS does this for you automatically with unicode-range. When you self-host, you take over that job.
Writing the @font-face rules
Each combination of weight and style needs its own @font-face rule, unless you use a variable font file.
@font-face {
font-family: "Inter";
src: url("/fonts/inter-regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Inter";
src: url("/fonts/inter-bold.woff2") format("woff2");
font-weight: 700;
font-style: normal;
font-display: swap;
}
body {
font-family: "Inter", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}Both rules share the family name "Inter". The browser picks the right file based on the font-weight the element asks for. If your CSS requests weight 700 and you declared only 400, the browser fakes bold by thickening the regular glyphs. The result is usually uglier than the real bold, so declare every weight you use.
For a variable font, one file covers a range of weights. You describe the range in font-weight:
@font-face {
font-family: "Inter";
src: url("/fonts/inter-variable.woff2") format("woff2");
font-weight: 100 900;
font-style: normal;
font-display: swap;
}With this rule, font-weight: 450 or font-weight: 650 works in your CSS. One request replaces several.
Preloading the critical file
A self-hosted font is discovered late. The browser has to download the HTML, then the CSS, parse the CSS, find an @font-face rule, and see that some text actually uses it. Only then does it request the file. A preload hint starts the download earlier:
<link rel="preload" href="/fonts/inter-regular.woff2" as="font" type="font/woff2" crossorigin>The crossorigin attribute is required for fonts, even when the file is on your own domain. Font requests use CORS mode. Without the attribute, the browser fetches the file twice, once for the preload and once for the real use, because the two requests do not match.
Preload only the one or two files needed for the first screen of text. Preloading every weight competes with other critical resources and can slow the page down.
Caching and headers
Third-party font services use long cache lifetimes, which is part of why they are fast. When you self-host, you set this yourself. Font files rarely change, so give them a long lifetime and a versioned or fingerprinted file name:
Cache-Control: public, max-age=31536000, immutableThis tells the browser it can keep the file for a year without checking again. If you later replace the font, change the file name, for example inter-regular.v2.woff2, so that visitors fetch the new file.
If your fonts live on a different domain than your pages, such as a CDN host, the server must also send Access-Control-Allow-Origin headers. Browsers enforce CORS on font files. Without the header, the font fails to load and you will see a CORS error in the console.
Performance trade-offs
Self-hosting is often described as faster. The truth depends on your setup.
Where self-hosting helps:
- One fewer connection. The browser does not need DNS lookup, TCP connection, and TLS setup for two extra hosts. If your page already has an open connection to your domain, the font request reuses it.
- No stylesheet round trip. With a Google Fonts
<link>, the browser must fetch the CSS before it learns the font file URLs. Your own@font-facerule is already in your CSS. - Control over caching and priority. You can preload, set headers, and subset exactly as you need.
Where it can hurt:
- No shared cache. Years ago, a font loaded on one site could be reused from the browser cache on another site that used the same Google Fonts URL. Modern browsers partition their caches by site, so this benefit has disappeared. That removes one of the old arguments against self-hosting.
- Your server must be fast. A small origin server far from the visitor can be slower than Google's global network. Putting fonts behind a CDN solves this.
- You maintain it. Updates, new versions of a family, subsets, and format changes are now your work.
The honest approach is to measure. Load the page with the Network panel open, with throttling set to a slow connection, and compare the time at which text appears in both setups.
Privacy and legal considerations
Every request to a third-party font host reveals information to that host. At minimum the host sees the visitor's IP address, the browser's user agent, and the page that referred the request. Whether that counts as personal data depends on the law that applies to you.
In 2022, a German regional court ruled that embedding Google Fonts from Google's servers, in a way that transmitted a visitor's IP address to Google without consent, violated the visitor's privacy rights under the GDPR. The decision led to a wave of warning letters to site owners in Germany. The ruling is limited to one court, but it shows that a font link can be a legal exposure in the European Union.
Google states that its Fonts service does not set cookies and that it collects only the data needed to serve the fonts. Adobe Fonts publishes its own privacy information. Neither statement changes the fact that the request reaches a third party. Whether you need to disclose it in a privacy policy, or obtain consent, is a legal question for your jurisdiction, not a technical one.
Self-hosting removes the question for fonts. The visitor's request goes only to your own server, which you already disclose in your privacy policy. This is the main reason many European sites self-host.
A decision checklist
Self-hosting is a good fit when:
- You use open-licensed fonts, such as Google Fonts families.
- You serve visitors in regions with strict privacy rules.
- You want full control over caching, preloading, and subsetting.
- Your site already sits behind a CDN.
Stay with the hosted service when:
- You use Adobe Fonts, where self-hosting is not permitted.
- You want automatic updates and automatic per-language subsetting.
- You have no one to maintain the files, and your privacy requirements allow third-party requests.
Verifying your setup
After switching, check three things in the browser's developer tools.
- In the Network panel, filter by "Font". Every font request should point at your own domain, and none at
fonts.gstatic.comoruse.typekit.net. - Check that each font file appears once. Two requests for the same file usually mean a missing
crossoriginattribute on the preload. - Check response headers for
Cache-Controland, on a separate font domain, forAccess-Control-Allow-Origin.
Also search your HTML and CSS for leftover references, such as an old <link> to fonts.googleapis.com or an @import line. A forgotten link keeps sending requests to Google and defeats the privacy goal.
Exercise
Your page preloads /fonts/inter-regular.woff2 with <link rel="preload" href="/fonts/inter-regular.woff2" as="font" type="font/woff2">. The Network panel shows the file downloaded twice. What is the likely cause, and how do you fix it?
Show answer
The preload is missing the crossorigin attribute. Font requests use CORS mode, so a preload without crossorigin does not match the later request from @font-face, and the browser fetches the file twice. Add crossorigin to the link tag: <link rel="preload" href="/fonts/inter-regular.woff2" as="font" type="font/woff2" crossorigin>.
Exercise
A colleague proposes self-hosting the Adobe Fonts typeface "Proxima Nova" to avoid third-party requests. Is this allowed, and what are the alternatives?
Show answer
No. Adobe Fonts licenses fonts for delivery through its own web projects and does not permit downloading the files to host yourself. The alternatives are to buy a web license for the typeface from a source that allows self-hosting, or to switch to an open-licensed typeface such as one from Google Fonts that can be self-hosted.
Exercise
Name two reasons self-hosting can be faster than a Google Fonts link, and one reason it can be slower.
Show answer
Faster: the browser avoids extra DNS, TCP, and TLS setup for two third-party hosts, and it does not need to fetch a stylesheet from another host before discovering the font file URL. Slower: if your origin server is slow or far from the visitor and you do not use a CDN, it may deliver files more slowly than Google's global network. Maintenance of subsets and updates is also now your responsibility.