Skip to main content
KadiCache
Browse 37 Docs Guides & Search

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.

Optimization/FontOptimizer.phpOptimization/FontCss.phpOptimization/Fonts/FontAssetDownloader.phpOptimization/ResourceHints.php
WP Admin -> KadiCache -> Fonts
MODULE 22 · 2X RETINA
Self-host Google Fonts locally, subset WOFF2 glyph ranges in the cloud, and synthesize metric-matched fallback @font-face rules.2880×1840 WebP
Quick Summary · 30-Second Operational SpecSource-Verified Guide
WP Admin Path
WP Admin -> KadiCache -> Fonts
Expected Outcome
0 Google Font Connections · Max 5 Safe WOFF2 Preloads
Key Marker / Engine
FontOptimizer.php | FontCss.php | ResourceHints.php
  • Self-Host Google Fonts (FontOptimizer.php + FontAssetDownloader.php): Downloads Google Fonts CSS and .woff2 files into wp-content/kadicache-assets/fonts/ so visitors load typography from your own domain with zero requests to fonts.googleapis.com or fonts.gstatic.com.
  • Enforce font-display: swap (FontCss.php): Automatically adds font-display: swap where missing across Google Fonts, inline @font-face blocks, 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 at 5 local .woff2 files to prevent bandwidth contention).
  • Smart Preconnect & DNS-Prefetch (Tools -> Proxy, 404 & Hints): Supports up to 20 validated 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:

  1. Connection #1 (fonts.googleapis.com): DNS lookup + TCP handshake + TLS negotiation just to download a 2 KB stylesheet.
  2. Connection #2 (fonts.gstatic.com): A second DNS lookup + TCP handshake + TLS negotiation to fetch the .woff2 binary 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!
  3. 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!

FIG 01Configuring Self-Host Google Fonts, font-display: swap, Excluded Google Fonts, and Preload Critical Local WOFF2 Fonts inside WP Admin -> KadiCache -> FontsZoom 2x

Complete Guide to Free Core Typography & Hint Controls#

SettingAdmin LocationBuilt-In Guardrail (FontOptimizer / ResourceHints)
Self-host Google FontsKadiCache -> FontsOpt-in background download of Google Fonts CSS & .woff2 into kadicache-assets/fonts/
Add missing font-display: swapKadiCache -> FontsFontCss::addSwapWhereMissing() patches @font-face rules lacking font-display
Excluded Google FontsKadiCache -> FontsKeep specific font families (Material Symbols*) on Google’s CDN if desired
Preload Critical Local WOFF2 FontsKadiCache -> FontsAccepts up to 5 same-origin .woff2 URLs; auto-adds crossorigin="anonymous"
Preconnect OriginsTools -> Proxy, 404 & HintsUp to 20 HTTPS/HTTP origins (root origin only, e.g. https://use.typekit.net)
DNS-Prefetch OriginsTools -> Proxy, 404 & HintsAuto-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:

  1. 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> via HookFreeTagProcessor (skipping <template> tags) and places resource hints immediately after charset and CSP meta tags!
  2. Mandatory crossorigin="anonymous" on Font Preloads: Even when a .woff2 font sits on your exact same domain, CSS @font-face fetches use anonymous CORS mode. Omitting crossorigin on <link rel="preload" as="font"> causes Chrome to download every font twice! KadiCache always emits as="font" type="font/woff2" crossorigin="anonymous".
  3. Hard 5-Font Preload Cap & .woff2 Validation (ResourceHints::sanitize()): Rejects .ttf/.otf or off-origin URLs in the local font preload box and caps preloads at 5 files so editors never choke mobile LCP bandwidth by preloading 14 font weights.
  4. Automatic CDN Preconnect: Whenever you configure a static asset CDN CNAME in WP Admin -> KadiCache -> CDN, ResourceHints adds <link rel="preconnect" href="https://cdn.example.com" crossorigin="anonymous"> automatically!
HTMLClean HTML <head> Output Generated by FontOptimizer & ResourceHints
<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 .woff2 URL: After enabling Self-host Google Fonts and visiting your homepage once in Incognito, open DevTools -> Network -> Font, right-click the primary .woff2 file used by your <h1> headline, choose Copy -> Copy URL, and paste it into Preload Critical Local WOFF2 Fonts (ResourceHints::sanitize() validates same-origin .woff2 automatically).
  • When to Use Preconnect Instead: Reserve Tools -> Proxy, 404 & Hints -> Preconnect Origins strictly for unavoidable third-party origins needed early on the page—such as https://use.typekit.net (Adobe Fonts) or https://js.stripe.com on checkout pages.
  • European GDPR Compliance Audits: Once Self-host Google Fonts is active, privacy scanners (such as Usercentrics, Cookiebot, or German GDPR font checkers) confirm 0 outbound connections to fonts.googleapis.com or fonts.gstatic.com across every cached page.

Frequently Asked Operational Questions

Does Self-host Google Fonts work when Google Fonts are loaded via Elementor, Astra, or @import rules?
Yes! FontOptimizer.php detects Google Fonts CSS v1 (/css?family=...) and v2 (/css2?family=...) <link> tags as well as @import declarations, downloads the modern .woff2 binaries in the background, and serves them locally.
What happens on the very first visit before FontAssetDownloader finishes downloading a font?
Self-hosting is completely non-blocking: until local font files are verified on disk, visitors cleanly receive normal typography without broken text or stalled PHP requests, and subsequent cached hits serve local files.
Why does ResourceHints reject full file URLs inside the Preconnect Origins box?
preconnect and dns-prefetch only establish early network connections to a scheme + host origin (such as https://scripts.vendor.com), not a file path. ResourceHints::sanitize() normalizes and validates origins automatically so invalid tags never enter <head>.
Should I put the same domain in both Preconnect and DNS-Prefetch?
No need—Preconnect already includes DNS lookup plus TCP and TLS handshakes, and ResourceHints.php automatically deduplicates dns-prefetch against preconnect_origins.
Does Add missing font-display: swap overwrite intentional font-display: optional rules?
No! FontCss::addSwapWhereMissing() only adds font-display: swap to @font-face blocks that omit a font-display descriptor, respecting explicit optional or fallback declarations.
Gergis — Lead Systems & Cache Architect
Principal WordPress & Cloud Edge Architect
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

apps/wordpress-plugin/src/Optimization/FontOptimizer.phpapps/wordpress-plugin/src/Optimization/FontCss.phpapps/wordpress-plugin/src/Optimization/Fonts/FontAssetDownloader.phpapps/wordpress-plugin/src/Optimization/ResourceHints.php
Was this engineering guide helpful?