John Downey
Nov 5 · 1 min read

I can’t be entirely sure because I haven’t actually implemented it myself yet, but I have enough knowledge about the fonts API that this seems to be the opposite of “quickly.”

  1. You can use a pipe in the url to request more than 1 font family, as follows:
@import url('https://fonts.googleapis.com/css?family=ABeeZee|Abel|Abhaya+Libre');

This’ll combine all of those fonts into a single file for you to request. Right now the little page you give as an example makes 1916 requests on my browser. There’s likely a limit as to how many families you can put in your URL (based on the limit of a valid URL length, if nothing else), but you could figure that limit out fairly quickly through trial and error to get a number n to take your requests and number of CSS files for the browser to process down to something more near 1916/n.

2. There’s actually a new API to make this even faster. It allows you to set a text parameter, so you could make requests like this instead:

@import url('https://fonts.googleapis.com/css2?family=ABeeZee&family=Abel&family=Abhaya+Libre&text=The+quick+brown+Fox+goes+to+Disney')

By setting the text to “The+quick+brown+Fox+goes+to+Disney”, the CSS files will be set up to point toward specific font files that only contain the glyphs needed to create that preview sentence. According to Google, this can decrease the font file sizes by up to 90%.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade