Hacker News new | ask | show | jobs
by partiallypro 2770 days ago
Couldn't you just download the Google fonts and serve them up yourself and use a Cloudflare rule to cache it on the edge, instead of going through all this work?
2 comments

Sure! But note that Google serves different font formats depending on your user-agent, so you'll have to make sure to cover all the different formats and do your own user-agent matching. And keep it updated as user-agent capabilities change over time. It's not quite as easy as it sounds.
You can specify multiple formats in the CSS. Just put them in order, and the browser will download the first one it supports.

And the css is going to be gzip'd anyway.. so we're talking a few extra bytes. Nothing that would make any difference in page load time.

There's no need for all of that extra work you listed. But I get why you want it to sound complicated, so people will use your work instead. Shouldn't you put a "I work at cloudflare" in there somewhere?

Google Fonts will serve a different .woff2 font file depending on the user-agent. You cannot accomplish that with just CSS. See https://news.ycombinator.com/item?id=8802748
the only difference is that on non-windows platforms google strips font hinting. That's just a (very minor) performance optimization done to reduce file sizes. Just download the windows version of the fonts (in all of the formats - woff, woff2, eof, etc).. the minor difference in size isnt worth the effort.

You can also just download the ttf files, and run them through a web font generator w/ proper support for hinting, etc... and then you'll have all of the formats you need.

If anyone wants to do this, I have used this tool in the past: https://google-webfonts-helper.herokuapp.com/fonts
And I wonder what speed tradeoff there will be for commonly cached/repeated fonts like Roboto, like maybe only makes since to inline less common fonts
AFAIK Google Fonts doesn’t allow browsers to cache the fonts for tracking purposes...
They do browser caching, but it's not as long as many would like for a static resource like a font. There is no proof they use Google Fonts for tracking, though, it's entirely possible they'll use it for that in the future...but I don't see a reason for them to do so. Google Analytics is already on most websites.