I want to defer font loading on my site inspired by deferred font loading logic for Smashing Magazine.
Main part of this is converting fonts to base64 and preparing your CSS file with that. My steps so far:
- Pick fonts on Google Web Fonts and download them.
- Use Font Squirrel Webfont Generator to convert downloaded TTF files to CSS file with base64 embedded WOFF fonts (Expert options -> CSS -> Base64 Encode).
- Load CSS file async (not important here).
CSS snippet for Open Sans Bold:
@font-face {
font-family: 'Open Sans';
src: url(data:application/x-font-woff;charset=utf-8;base64,<base64_encoded>) format('woff');
font-weight: 700;
font-style: normal;
}
The problem is, that converted fonts looks a lot different. E.g. here Open Sans Bold:
Especially notice accents way off and absolutely horrible letter 'a'. Other font families and variants looks very noticeably different too (size and shape distortions, etc.).
So the question is: How do you properly encode TTF files from Google Web Fonts (or any other source) to base64 format and use it so the result is identical to the original file?