| permalink |
|---|
/index.html |
Website (Git Pages)
Many of us use Google fonts via a CDN. However, Germany has decided that this contravenes GDPR, leaving site owners open to litigation.
We can still display Google fonts by:
Note: This page concentrates on Google Fonts, but the same principles apply to any other kind of web font.
Font Squirrel This worked for "Roboto" but failed with the static font versions of both "Lato" and "Open Sans".
Creative Fabrica I used this for "Lato" and "Open Sans" static files. I had to upload each variant, one at a time.
I was advised to preload the fonts in the head of the html page. This is supposed to speed up the delivery of the fonts and increase Google's Core Web Vitals (CWVs) performance. However, I saw warnings after doing this (see Testing/Firefox and Firefox Developer Edition, below).
<head>
<link
rel="preload"
href="roboto-light-webfont.woff2"
as="font"
type="font/woff2"
crossorigin="anonymous"
/>
<link
rel="preload"
href="roboto-regular-webfont.woff2"
as="font"
type="font/woff2"
crossorigin="anonymous"
/>
<link
rel="preload"
href="roboto-medium-webfont.woff2"
as="font"
type="font/woff2"
crossorigin="anonymous"
/>
...
<!-- CSS file comes after preload -->
</head>@font-face {
font-family: "Roboto";
font-weight: 300;
src: url("roboto-light-webfont.woff2") format("woff2"), url("roboto-light-webfont.woff")
format("woff");
}
/** Regular: 400 **/
@font-face {
font-family: "Roboto";
font-weight: 400;
src: url("roboto-regular-webfont.woff2") format("woff2"), url("roboto-regular-webfont.woff")
format("woff");
}
/** Medium: 500 **/
@font-face {
font-family: "Roboto";
font-weight: 500;
src: url("roboto-medium-webfont.woff2") format("woff2"), url("roboto-medium-webfont.woff")
format("woff");
}The bulk of the information came from Self-hosting fonts explained (including Google fonts) // @font-face tutorial (YouTube). Information on preloading/CWVs, and non-GDPR compliance emerged from a comments thread on the same page.