ARTICLE - Dev Stack & Tools

Self-Hosting Google Fonts

Self-hosting changes font delivery and maintenance, not the font license. Check actual requests, glyph coverage, and caching before assuming it improves speed or visitor privacy.

2026-11-25 16IDC Original 10 views
Advertisement

Using Google Fonts can require the browser to contact third-party font domains. Serving the files and stylesheet through a delivery path you control reduces that dependency, but performance, visitor data flows, and maintenance depend on the actual deployment. This guide covers same-origin files and a bundler-based alternative, with checks for each.

Choose a delivery path

The diagram distinguishes direct browser requests to Google from self-hosted delivery. A same-origin CDN can sit behind the site; a CDN on another origin requires a cross-origin response check.

Font delivery request paths Direct Browser Google CSS and font Third-party requests Same-origin Browser Site CSS and font Manage file versions Scope: request destinations, not a latency or compliance claim
Figure 1: Font delivery request paths (Source: illustrative request destinations)
Path When it fits Responsibility
Google Fonts links Browser access to Google is acceptable and reachable Check privacy requirements and reachability
Manual same-origin hosting You can manage static files and CSS Select files, check licenses, cache and update
Fontsource build The project has a bundler that handles CSS imports Lock dependencies and check output and subsets

web.dev's font guide notes that third-party delivery usually requires additional cross-origin connections, but caching, file size, and network conditions also affect the result. A domain you own is not proof of speed or privacy compliance: a CDN operator may still receive request data.

Deploy and verify manually

You need access to the site's HTML, CSS, and static files, plus an Inter regular weight 400 WOFF2 file licensed for deployment. Download the family from Google Fonts and check its accompanying license. If the download lacks WOFF2, generate it using a trusted conversion or build process. The filename below is a deployment convention, not a guaranteed download name.

  1. Copy or convert the file to /assets/fonts/inter-regular.woff2 in the site's public directory; the path must be reachable from the site root after deployment. Retain the previous CSS and font files for rollback.
  2. Add the following to the site's existing stylesheet and ensure the page loads that stylesheet. The example has no unicode-range; confirm the file actually covers the characters you need.
@font-face {
  font-family: "Inter Local";
  src: url("/assets/fonts/inter-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
body {
  font-family: "Inter Local", system-ui, sans-serif;
}

Verify: open a page and filter Network by Font in developer tools. Text using this family should trigger the local file request; inspect rendered fonts to confirm Inter is used. CJK or other characters absent from the file fall back to a system font. To require a particular CJK family, deploy it separately and test its coverage.

  1. Add a preload in the HTML head only after confirming the file is used above the fold and measuring a benefit:
<link rel="preload" href="/assets/fonts/inter-regular.woff2"
      as="font" type="font/woff2" crossorigin="anonymous">

Verify: in Network, check that the same URL is preloaded and used for rendering. For an unused preload or duplicate request, check the path, query parameters, and crossorigin. Even same-origin font preloads must match anonymous CORS mode; see MDN's preload documentation.

  1. Remove the old remote Google Fonts stylesheet and related preconnects, deploy, and clear caches. Reload representative pages with Network caching disabled and look for requests to fonts.googleapis.com or fonts.gstatic.com. Check other components, themes, and embeds, not just one page.

For a 404, check the deployed path and capitalization first. For a blocked cross-origin font, inspect the font response's Access-Control-Allow-Origin against the site origin. If files or glyphs fail, restore the saved CSS and font files; if the old route is unavailable, temporarily use the system font stack. Compare loading and layout on representative user networks before assuming self-hosting is faster.

Build with Fontsource

If the project already has a bundler that handles CSS imports, run this in the project directory:

npm install @fontsource/inter

Verify: the installation should add @fontsource/inter to the project dependencies. Commit the lockfile and upgrade according to the project's process; never commit package-manager credentials.

Import the regular weight in the application entry and use font-family: "Inter", system-ui, sans-serif in the application stylesheet:

import "@fontsource/inter/400.css";

Verify: run the project's own build and deployment, then check that the font request comes from the intended site or CDN and that rendered text uses Inter. Fontsource's installation guide requires CSS import support; its default CSS uses unicode-range so the browser requests subsets needed by the page. If a static subset must be restricted, use the subset documentation and check for missing glyphs. Files in build output are not necessarily all downloaded on each visit.

Limitations

  • Check each font's license: self-hosting does not change it. SIL OFL requires the copyright notice and license with redistributed copies; a modified version cannot use an explicitly designated Reserved Font Name without written permission. Check whether the individual font has one rather than assuming every change requires renaming. See the SIL OFL text.
  • Privacy is not just the domain: a CDN behind your domain, logs, and other third-party components may still process visitor information. Assess legal basis and disclosures against actual data flows and applicable jurisdictions.
  • Caching and rollback: long cache lifetimes suit immutable versioned files. For an update, publish a new filename before changing CSS, and retain the old file until old pages and caches no longer reference it.
  • Coverage and compatibility: WOFF2 suits modern browsers; assess legacy browser needs, CJK subsets, variable weights, and licenses against the target environment. Preloading can compete with other resources and is optional.

FAQ

Why are Google font requests still visible after self-hosting?

A remote stylesheet, theme, or embedded component may still reference Google. Reload representative pages with caching disabled, use Network to identify each initiator, and replace the relevant references. Also inspect build output: changing one stylesheet does not establish that the entire site has stopped making third-party font requests.

Does font preload always improve the first screen?

No. Preload starts a download early even if the page ultimately does not use it, and can take bandwidth from other critical resources. First identify the file actually used above the fold, then compare the network waterfall and layout with and without preload. Remove it if it provides no benefit.

Can a Latin font display CJK text?

Only if the file contains the necessary glyphs. Inspect rendered fonts on pages containing the languages and unusual characters your application uses. If coverage is missing, deploy a CJK family with suitable rights and coverage, or accept fallback to a system font.

Related Providers

  • Google Fonts: find font families, source files, and their licenses.
  • Fontsource: manage font files and CSS with npm in an existing build pipeline.

Community & Resources

Original source: 16IDC Original ↗