Self-host web fonts instead of loading them from Google
Problem: This site uses IBM Plex Mono and Space Grotesk. The quick way is a <link> to fonts.googleapis.com.
Why: Then every page view sends the visitor’s IP address to Google. In January 2022 the Munich Regional Court (LG München I, 3 O 17493/20) ruled that doing this without consent breaks the GDPR and awarded the visitor damages. A wave of warning letters to German site owners followed.
Fix: Install the fonts from npm with Fontsource and import the CSS. The bundler copies the woff2 files into the site, so nothing is loaded from a third party:
import '@fontsource/ibm-plex-mono/400.css';
import '@fontsource/space-grotesk/700.css';
- One import per weight. Only import the weights the CSS actually uses.
- The generated
@font-facerules useunicode-range, so browsers download only the subsets a page needs. - Side benefit: no extra connection to another domain before text can render.
Remember: On any site with visitors from the EU, self-host fonts. Never link fonts.googleapis.com.