News for hackers. Stuff that matters.
Re:The Fastest Google Fonts by csswizardry on Thursday May 28, 2020 @08:08PM (#23344706)
OP here. Inlining CSS won’t work as the request is UA-sniffed.
Re:The Fastest Google Fonts by r1ch on Thursday May 28, 2020 @09:29PM (#23345324)
Modern browsers are smart enough to only download the required file type, sniffing is unnecessary the vast majority of the time and you save an entire 3rd party connection.

There are tools like https://google-webfonts-helper.herokuapp.com/fonts which will get you the needed css.

Re:The Fastest Google Fonts by csswizardry on Friday May 29, 2020 @05:19AM (#23347948)
I know how browsers work, but thanks.

The tool you linked does not solve the same problem, as the problems isn’t file types but URIs. Google is able to provide the tiniest possibly font files by hinting them for the specific browser/platform requesting them. We never consistently or predictably know the resultant URI of a Google Fonts-hosted font file. Here is a Tweet to the same effect from two days ago. Believe me, I’ve researched this :(

https://twitter.com/csswizardry/status/1265716520346320903

Re:The Fastest Google Fonts by r1ch on Friday May 29, 2020 @01:50PM (#23353170)
The URLs on gstatic.com are static. I've been doing this for years in production without issues.
Re:The Fastest Google Fonts by cmbuckley on Friday May 29, 2020 @08:51PM (#23357421)
The fonts are static, but the CSS (from fonts.googleapis.com), and the font files it references, vary depending on the User-Agent. For instance, with a Chrome UA it will request WOFF files; with a blank UA it may request TTF files.
Re:The Fastest Google Fonts by r1ch on Saturday May 30, 2020 @07:38AM (#23360419)
The idea is that you take all the links to the different font types and put them directly in your local CSS. Your browser knows which formats it supports, if you have TTF and WOFF2 fonts linked, Chrome will only download the WOFF2 version. No need to send an extra 3rd party request just to get a piece of CSS that only links a single file type.
Re:The Fastest Google Fonts by cmbuckley on Saturday May 30, 2020 @06:26PM (#23365359)
Well yes, of course you can do that. But at that point, why would you reference third-party font URLs, instead of self-hosting them? (The article pretty much begins by stating that this is the fastest option.)

If performance is your utmost priority, forego web fonts entirely. If you value performance but want the benefit of a web font, self-host your CSS and fonts. If the convenience of Google Fonts is appealing, the suggestions here can improve first-paint performance. Different projects will have different trade-offs.

Re:The Fastest Google Fonts by toast0 on Friday May 29, 2020 @01:57AM (#23346682)
You could use a couple microseconds on the server to inline CSS to match the HTTP U-A; assuming whatever you needed to know is still in there by the grace of Google whenever they slush up the U-A strings.