Show HN: Download and inline Google web fonts from the command-line
github.com
github.com
It makes my life a little more convenient. https://github.com/steakejjs/OpenSans-CSS/blob/master/OpenSa...
I got the woff files, base64'd them, and then threw the output into several CSS files.
Words of warning, If you use Content Security policy, you must allow Unsafe Inline for the style-src directive.
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):
webfont-dl -d "https://github.com/steakejjs/OpenSans-CSS/raw/master/OpenSans.css" \
-o css/font.css --font-out=font --css-rel=../font --woff=linkYou can install this via:
npm install -g webfont-dl
And download a set of fonts like so: webfont-dl "http://fonts.googleapis.com/css?family=Crimson+Text:400,400italic|Raleway:500" \
-o css/font.css - 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.[1] https://developers.google.com/web/fundamentals/performance/c...
It'd be nice to have a way of clients caching webfonts. Fonts could have a signature (checksum) and loaded from the user cache.
because if yes, then i rather let the font served by Google fonts.
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".