Self-Host Google Fonts Locally, font-display: swap & Resource Hints
Download Google Fonts to kadicache-assets/fonts for GDPR privacy and single-connection speed, enforce font-display: swap, preload up to 5 critical WOFF2 files, and tune Preconnect.
- Self-Host Google Fonts (
FontOptimizer.php+FontAssetDownloader.php): Downloads Google Fonts CSS and.woff2files intowp-content/kadicache-assets/fonts/so visitors load typography from your own domain with zero requests tofonts.googleapis.comorfonts.gstatic.com. - Enforce
font-display: swap(FontCss.php): Automatically addsfont-display: swapwhere missing across Google Fonts, inline@font-faceblocks, and minified stylesheets—eliminating Flash of Invisible Text (FOIT). - Validated Critical Font Preloads (
ResourceHints.php): Emits spec-compliant<link rel="preload" as="font" type="font/woff2" crossorigin="anonymous">hints (capped at5local.woff2files to prevent bandwidth contention). - Smart
Preconnect&DNS-Prefetch(Tools -> Proxy, 404 & Hints): Supports up to20validated external origins and automatically preconnects your configured CDN hostname.
Why Self-Hosting Google Fonts Improves Both Mobile Speed & GDPR Privacy#
When your WordPress theme or Elementor global kit loads <link href="https://fonts.googleapis.com/css2?family=...">, every first-time mobile visitor pays two separate cross-origin connection penalties:
- Connection #1 (
fonts.googleapis.com): DNS lookup + TCP handshake + TLS negotiation just to download a 2 KB stylesheet. - Connection #2 (
fonts.gstatic.com): A second DNS lookup + TCP handshake + TLS negotiation to fetch the.woff2binary files—because modern browser HTTP Cache Partitioning isolates cached Google Fonts per top-level domain, even common fonts like Inter, Roboto, or Poppins are never shared from other websites! - GDPR Visitor IP Exposure: Connecting directly to Google’s font servers sends every European visitor’s IP address to Google prior to cookie consent.
Enabling Self-host Google Fonts (local_fonts_enabled) in KadiCache Free Core (FontOptimizer.php + FontAssetDownloader.php) eliminates both external domains completely: font binaries and rewritten @font-face rules stream over your existing warm HTTP/2 or HTTP/3 origin connection with 1-year immutable browser caching!
Complete Guide to Free Core Typography & Hint Controls#
| Setting | Admin Location | Built-In Guardrail (FontOptimizer / ResourceHints) |
|---|---|---|
| Self-host Google Fonts | KadiCache -> Fonts | Opt-in background download of Google Fonts CSS & .woff2 into kadicache-assets/fonts/ |
Add missing font-display: swap | KadiCache -> Fonts | FontCss::addSwapWhereMissing() patches @font-face rules lacking font-display |
| Excluded Google Fonts | KadiCache -> Fonts | Keep specific font families (Material Symbols*) on Google’s CDN if desired |
| Preload Critical Local WOFF2 Fonts | KadiCache -> Fonts | Accepts up to 5 same-origin .woff2 URLs; auto-adds crossorigin="anonymous" |
| Preconnect Origins | Tools -> Proxy, 404 & Hints | Up to 20 HTTPS/HTTP origins (root origin only, e.g. https://use.typekit.net) |
| DNS-Prefetch Origins | Tools -> Proxy, 404 & Hints | Auto-deduplicated against Preconnect (array_diff) so hints never double-print |
Inside ResourceHints.php: Placement Accuracy & Mistake-Proof Validation#
Many manual header-snippet plugins break font preloading or HTML encoding validation through subtle markup mistakes. ResourceHints.php enforces W3C browser rules automatically:
- Exact
<head>Offset After<meta charset>&CSP(ResourceHints::preloadOffset()): Injecting<link rel="preload">above<meta charset="utf-8">pushes<meta charset>past Chrome’s early byte window, while injecting it above<meta http-equiv="Content-Security-Policy">bypasses meta-CSP governance. KadiCache parses<head>viaHookFreeTagProcessor(skipping<template>tags) and places resource hints immediately after charset and CSP meta tags! - Mandatory
crossorigin="anonymous"on Font Preloads: Even when a.woff2font sits on your exact same domain, CSS@font-facefetches use anonymous CORS mode. Omittingcrossoriginon<link rel="preload" as="font">causes Chrome to download every font twice! KadiCache always emitsas="font" type="font/woff2" crossorigin="anonymous". - Hard
5-Font Preload Cap &.woff2Validation (ResourceHints::sanitize()): Rejects.ttf/.otfor off-origin URLs in the local font preload box and caps preloads at5files so editors never choke mobile LCP bandwidth by preloading 14 font weights. - Automatic CDN Preconnect: Whenever you configure a static asset CDN CNAME in
WP Admin -> KadiCache -> CDN,ResourceHintsadds<link rel="preconnect" href="https://cdn.example.com" crossorigin="anonymous">automatically!
<head>
<meta charset="UTF-8">
<link rel="preconnect" href="https://cdn.example.com" crossorigin="anonymous">
<link rel="preload" href="https://example.com/wp-content/kadicache-assets/fonts/plus-jakarta-700.woff2"
as="font" type="font/woff2" crossorigin="anonymous">
<!-- Local Google Fonts stylesheet with font-display: swap -->Choosing Which Local .woff2 Files Belong in the Critical Preload Box#
Because preloaded fonts download at high browser priority alongside your critical stylesheet and hero image, discipline matters more than quantity inside Preload Critical Local WOFF2 Fonts:
- Rule of 1 to 2 Weights: On most sites, preload only your primary heading weight (for example
plus-jakarta-sans-700-latin.woff2) and—if body copy appears prominently above the fold—your regular body weight (inter-400-latin.woff2). Leave italic, light (300), and footer icon weights un-preloaded so they never compete with your hero image for early cellular packets! - How to Copy the Exact Local
.woff2URL: After enabling Self-host Google Fonts and visiting your homepage once in Incognito, open DevTools -> Network -> Font, right-click the primary.woff2file used by your<h1>headline, choose Copy -> Copy URL, and paste it intoPreload Critical Local WOFF2 Fonts(ResourceHints::sanitize()validates same-origin.woff2automatically). - When to Use
PreconnectInstead: ReserveTools -> Proxy, 404 & Hints -> Preconnect Originsstrictly for unavoidable third-party origins needed early on the page—such ashttps://use.typekit.net(Adobe Fonts) orhttps://js.stripe.comon checkout pages. - European GDPR Compliance Audits: Once
Self-host Google Fontsis active, privacy scanners (such as Usercentrics, Cookiebot, or German GDPR font checkers) confirm0outbound connections tofonts.googleapis.comorfonts.gstatic.comacross every cached page.
Frequently Asked Operational Questions
Does Self-host Google Fonts work when Google Fonts are loaded via Elementor, Astra, or @import rules?
What happens on the very first visit before FontAssetDownloader finishes downloading a font?
Why does ResourceHints reject full file URLs inside the Preconnect Origins box?
Should I put the same domain in both Preconnect and DNS-Prefetch?
Does Add missing font-display: swap overwrite intentional font-display: optional rules?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.