I got tired of using font CDNs, didn't like extra round trips for the woff files, and I also really liked open-sans, so I made an OpenSans.css which inlines all the OpenSans fonts.
Also, I hooked up support for data: URLs so you can use your stylesheet as a source for fonts (if someone was interested in extracting the .woff files back to individual files, for instance):
I've been fighting the flash of invisible content problem while using Google's web fonts on Safari, so I bit the bullet and built a command-line tool that would both 1) host them locally and 2) inline the woff version that's supported by most modern browsers as a data: URL.
It avoids the flash by effectively blocking load. It's not documented, but you can infer it:
- CSS blocks rendering until download [1]
- Inlining a font in CSS makes it part of the CSS
- Fonts inlined in CSS block rendering until download
You can get a similar effect by using a webfont loader and hiding the body until the font loads. The utility uses a strong name for downloading font resources, so if you want to go down this road and use a long expiry for the font resources that'll work as well.
I was aware of the technique of hiding the body, but that for me is unacceptable. It causes further delays to get content on the page. This inlining of the fonts is quite interesting.
It'd be nice to have a way of clients caching webfonts. Fonts could have a signature (checksum) and loaded from the user cache.
I'm curious. If visitors visit a site using a font served by Google fonts and visit another using the same font, will it use the cache from the browser?
because if yes, then i rather let the font served by Google fonts.
The fonts themselves are cached for a "long time", but the CSS that links the font to a @font-face declaration expires far more frequently (ie: less than a day).
In my testing on slow connections, serving fonts from Google's site generally results in missing text on iOS devices and Safari if the cache is cold.
By inlining a woff font in the stylesheet you take a bigger hit on the first request to your site (~110kB for my site with three web fonts), but you never see the missing text. Because I'm inlining this in my CSS, I can ensure that it's strongly cached for return visitors and they pay this only once.
It's all a tradeoff that you have to judge for yourself: "What are the chances that a given user has a specific font that you've decided to use cached?" vs "What experience do you want the user to have on a cold cache".
It makes my life a little more convenient. https://github.com/steakejjs/OpenSans-CSS/blob/master/OpenSa...