A quick look at Typekit

Vincent Bernat

Back in the dark ages of the web, be­fore the in­tro­duc­tion of CSS 3, browsers could only dis­play fonts avail­able on the client sys­tem. Thanks to the in­tro­duc­tion of @font-face and its now wide­spread sup­port, this is over. Now, Web de­sign­ers have ac­cess to a large se­lec­tion of fonts and most users will be able to ap­pre­ci­ate them.

Type­kit pro­vides a sub­scrip­tion-based li­brary of hosted, high-qual­ity fonts to use on web­sites. I ex­pose here my own, mostly un­e­d­u­cated1 on the ty­po­graphic side, look on this service.

Fonts embedding 101#

There are sev­eral ways to em­bed fonts for the Web. Let’s have a look at the most com­mon ones.

Self-hosting and @font-face#

A first pos­si­bil­ity is to host fonts your­self and pro­vide a CSS file with the ap­pro­pri­ate @font-face dec­la­ra­tions. There are five im­por­tant things to know:

  1. There is no com­mon for­mat. You will need to host dif­fer­ent ver­sions of the same font to sup­port most browsers.
  2. As usual, In­ter­net Ex­plorer comes with its own quirks that you need to work around.
  3. Most browsers en­force a same ori­gin pol­icy. You need to serve your fonts from the same do­main as the re­quest­ing page. You can cir­cum­vent such a lim­i­ta­tion by en­abling cross-ori­gin re­source shar­ing: add an Access-Control-Allow-Origin header when serv­ing fonts.
  4. Fonts are un­likely to change. To lever­age caching, con­fig­ure an ex­plicit ex­pi­ra­tion date far in the fu­ture. Some­thing like 30 days.
  5. There is no MIME types reg­is­tered for fonts. Don’t bother set­ting one, even if Google Chrome likes to com­plain about them in the console.

One great re­source is Font Squir­rel which pro­vides kits with fonts and the ap­pro­pri­ate CSS dec­la­ra­tions. You choose your font fam­ily (or up­load one of your own), the for­mats that you want to use (check them all) and you will get a ZIP ar­chive with all fonts and a CSS file. You may want to tweak it a bit to en­able au­to­matic use of the bold vari­ant when needed and to use a lo­cal copy if avail­able. For ex­am­ple, if you choose Crim­son, an old­style type­face, you may want to de­clare the bold ver­sion with font-weight: bold and add lo­cal names:

@font-face {
    font-family: 'Crimson';
    src: url('Crimson-Bold-webfont.eot');
    src: local('Crimson Bold'), local('Crimson Text Bold'),
         url('Crimson-Bold-webfont.eot?#iefix') format('embedded-opentype'),
         url('Crimson-Bold-webfont.woff') format('woff'),
         url('Crimson-Bold-webfont.ttf') format('truetype'),
         url('Crimson-Bold-webfont.svg#CrimsonBold') format('svg');
    font-weight: bold;
    font-style: normal;
}

Google Web Fonts#

For open-source fonts, you can also use Google Web Fonts in­stead of host­ing the files your­self. Build a col­lec­tion of fonts and choose the vari­ants that you want to use for each of them. You will then be pro­vided with a code snip­pet to paste in the <head> el­e­ment of your page. For ex­am­ple, for Crimson:

<link href='http://fonts.googleapis.com/css?family=Crimson+Text:400,700,400italic'
      rel='stylesheet' type='text/css'>

Why choose this so­lu­tion over self-hosting?

  1. You do not use your own band­width to serve fonts. This may be im­por­tant if you pay for it.
  2. Google uses its own CDN to serve fonts. If you don’t use a CDN your­self, this can be a ma­jor per­for­mance im­provement.
  3. Caching is more ef­fi­cient since many sites will use the same font.
  4. It is eas­ier to do it right.

Un­less you are con­cerned about Google track­ing your users,2 I think this is a bet­ter so­lu­tion than self-host­ing. Quick de­liv­ery of fonts is pretty im­por­tant since con­tent ren­der­ing can be de­layed by them.

If you would like to use com­mer­cial fonts, like Adobe Min­ion Pro or Paratype Fu­tura PT, a con­ve­nient op­tion is to rent them. Type­kit is ser­vice pro­vid­ing such an op­tion. Pric­ing de­pends on vol­ume and the num­ber of fonts you want to have ac­cess to. There is a free plan and the first paid plan is US$24.99 per year. Other sim­i­lar ser­vices ex­ist. Feel free to compare.

Once reg­is­tered, the work­flow is sim­i­lar to Google Web Fonts. You choose your fonts, as­sem­ble them in a “kit” and pub­lish it. In­stead of di­rectly pro­vid­ing a CSS file, Type­kit pro­vides some Java­Script which will in turn down­load a CSS file con­tain­ing all fonts in the ap­pro­pri­ate for­mat for the browser (on most browsers, fonts are inlined).

<script type="text/javascript"
        src="//use.typekit.com/tyt0atd.js"></script>
<script type="text/javascript">
  try{Typekit.load();}catch(e){}
</script>

Typekit: the good parts…#

So, why choose Type­kit? First, there is the very large choice of fonts. The first paid plan comes with more than 500 fonts from about 80 foundries. There are about a hun­dred serif fonts and a cou­ple hun­dred sans serif ones.

Type­kit pro­vides a con­ve­nient in­ter­face to browse fonts. You can ei­ther search fonts by name or by char­ac­ter­is­tics. In the last case, you can fil­ter on prop­er­ties like the clas­si­fi­ca­tion (serif, sans serif, dec­o­ra­tive, etc.), weight, width, con­trast, x-height, rec­om­mended use or lan­guage sup­port. Once a font is se­lected and added to your kit, you can eas­ily choose what vari­ants you want. The kit to­tal size is displayed.

If you hap­pen to meet any prob­lem or have some ques­tions, Type­kit sup­port is very re­spon­sive. I got clear and crisp an­swers in less than a few hours on the weekend.

…and the bad ones#

Un­for­tu­nately, Type­kit has also some short­com­ings. One of the most com­monly cited is that Java­Script is manda­tory. No Java­Script, no fonts. If you want to dis­play the ap­pro­pri­ate fonts for users with­out Java­Script, you should just not use Typekit.

Not free, nor free#

While Type­kit of­fers some open-source fonts, most of them are not. More­over, only a few of them are avail­able in the free plan. While I would pre­fer to use open-source fonts, I do not con­sider this a strong re­quire­ment: if you are dis­sat­is­fied for some rea­son, switch­ing back to open-source fonts (or an­other ser­vice) is fast and easy.

I like serif fonts a lot and they get less at­ten­tion from the FLOSS world: it is dif­fi­cult to find one whose read­abil­ity on screen is ex­cel­lent. Droid Serif is a nice font but is a bit too black for me. Maybe Cardo would be a good match.

You may dis­agree and in this case, Google Web Fonts or self-host­ing seem the per­fect match.

Difficulty to choose and test fonts#

While brows­ing fonts is easy and smooth, choos­ing and test­ing them is an­other mat­ter. For ex­am­ple, Type­kit is miss­ing some in­ter­face to com­pare font ren­der­ing for whole para­graphs at a given size. It also misses a way to check how two fonts ren­der to­gether, one for head­ings and one for para­graphs. Here, Google Web Fonts is more versatile.

Things be­come re­ally dif­fi­cult when you want to test your se­lected fonts for real. Ex­cept if you have in­vested into one of the ex­pen­sive plans, you can only in­clude a lim­ited num­ber of fonts in your kit. Each time you want to try an­other set of fonts, you need to mod­ify your kit and wait for it to be dis­trib­uted across Type­kit net­work. You may have to wait five or ten min­utes be­tween each change!

An­other in­con­ve­nience is that once you pub­lish your site, any change to the kit will af­fect the pub­lished ver­sion. There­fore, you need to use a sec­ond kit for de­vel­op­ment and play back and forth with these two kits.

What would be con­ve­nient here is a spe­cial kit with all fonts from the li­brary with re­stricted ac­cess to some IP to avoid abuse. This is some­thing done by Font­deck, a com­petitor.

Poor subset support#

Be­cause you want to keep the font size small (about 30 kB for each vari­ant), Type­kit usu­ally pro­poses two sub­sets: the de­fault one con­tains only latin char­ac­ters and the com­plete one with all glyphs. If some glyph is ab­sent from the de­fault sub­set, you need to use the com­plete one which is roughly two to four times the size of the de­fault one. This is a bit huge for only one character.

What would be nice is to have sub­sets for each lan­guage. In my case, I would take a French sub­set be­cause I need the “œ” glyph which ap­pears in French in words like “cœur” (heart or core) or “œil” (eye). I do not want to se­lect the com­plete sub­set just for this character.

When a glyph is ab­sent, the next font in the CSS stack is used. For ex­am­ple, if the se­lected font is FF Tisa Web Pro and the next font in the stack is Droid Serif, here is how the word “cœur” may be ren­dered. On the first line, FF Tisa Web Pro con­tains the ap­pro­pri­ate glyph. On the sec­ond line, the glyph is ab­sent and taken from Droid Serif. Since x-height and con­trast are a bit dif­fer­ent, the re­placed glyph seems out of tone. At small sizes, the dif­fer­ence ac­counts for more than 10%.

Various rendering of word "cœur"
Rendering when glyph is present, substituted by a glyph from another font or emulated. Rendering at 72px and 16px (zoomed).

I have also added a third line where the lig­a­ture is built from “o” and “e” and the fol­low­ing style is ap­plied to “e”:

.lf-ligature {
    margin-left: -0.172em;
    zoom: 1; /* Here to trigger hasLayout on IE7 */
}

As you can see, the re­sult seems good. I have a piece of Java­Script turn­ing a lig­a­ture into the ap­pro­pri­ate markup. It can be ex­tended to han­dle more lig­a­tures and could be adapted to han­dle other com­posed char­ac­ters (like the ones in “An­tonín Dvořák”).

Defective caching#

Up­date (2012-08)

Type­kit im­proved the way fonts are served. It is prob­a­ble that this para­graph is now void.

Be­cause a doc­u­ment can only be ren­dered af­ter the fonts have been loaded,3 it is pretty im­por­tant to de­liver fonts as fast as pos­si­ble. Type­kit uses Edge­cast as a CDN and DynECT for DNS hosting.

Two files are down­loaded. Both of them are hosted on use.​typekit.​com. The first one is a script that will act as a loader. Based on the char­ac­ter­is­tics of your browser, it will choose how to down­load the re­quested fonts for best ren­der­ing. The sec­ond file is gen­er­ally a big CSS file con­tain­ing the fonts.

Here are the head­ers re­turned for the first file:

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=300
Content-Encoding: gzip
Content-Type: text/javascript
Date: Tue, 08 Nov 2011 18:34:16 GMT
ETag: "388467610+gzip"
Expires: Tue, 08 Nov 2011 18:39:16 GMT
Last-Modified: Sat, 05 Nov 2011 09:31:57 GMT
Server: ECS (cdg/D624)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 7440

First, no­tice that the con­tent is served com­pressed. Good point. The next head­ers to look at are Cache-Control, Date, ETag and Expires: the server re­quests the con­tent to be cached for 5 min­utes. When the browser no­tices that its copy is out-of-date, it will is­sue a new re­quest in­clud­ing a If-None-Match: 388467610+gzip header. Un­less the kit has been mod­i­fied, the server will an­swer with 304 Not Modified and no con­tent. The copy of the browser will be valid for an­other 5 min­utes. This means that af­ter 5 min­utes, at least 3 round-trips are needed to check if our fonts are up-to-date.

Worse, some­times, Type­kit servers may be just slow. They can wait one sec­ond be­fore an­swer­ing, just to send a 304. Since the first file is a script em­bed­ded in <head>, the whole page is blocked un­til you get the an­swer. Here is an il­lus­tra­tive ex­am­ple with Chromium 14 where a page us­ing Type­kit is loaded while all static as­sets are in the nav­i­ga­tor cache and things have gone wrong (which is pretty rare):

Screenshot of Chromium Inspector
Timeline view when loading a page with Typekit embedded

Since fonts are needed, the ren­der­ing has been paused for 3.5 sec­onds un­til Type­kit was fully loaded. If we look more closely, we may also no­tice we got a sta­tus 200 from the server in­stead of 304. Here is an ex­cerpt of the browser request:

GET /tyt0atd.js HTTP/1.1
Host: use.typekit.com
Connection: keep-alive
Accept-Encoding: gzip,deflate,sdch
If-None-Match: "2200251225+gzip"
If-Modified-Since: Thu, 10 Nov 2011 11:38:11 GMT

And here is an ex­cerpt of the an­swer headers:

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=300
Content-Type: text/javascript
Date: Fri, 11 Nov 2011 17:10:03 GMT
ETag: "2200251225"
Expires: Fri, 11 Nov 2011 17:15:03 GMT
Last-Modified: Thu, 10 Nov 2011 11:38:11 GMT
Server: EOS (lax001/54E5)
Content-Length: 25755

What hap­pened? For some un­known rea­son, the server de­nied the ac­cess to the com­pressed ver­sion of the re­source: there is no Content-Encoding: gzip while the browser did send Accept-Encoding: gzip. The tag pro­vided by the browser (2200251225+gzip) came from the com­pressed re­source and there­fore does not match. RFC 2616 re­quests If-Modified-Since header to be ig­nored if the tag does not match. Con­se­quently, the server an­swers with 200 OK and re­sends the whole file. The same prob­lem hap­pened with the CSS file. Let me stress again how im­por­tant the prob­lem is: we had to down­load again the two files but we also down­loaded the non-com­pressed version.

Now, let’s sup­pose that we did not run into this prob­lem and the server an­swered with 304 Not Modified. The re­sult is still not sat­is­fac­tory: we would have waited 1.3 sec­onds to get both an­swers from the server. Keep in mind that most of the time, Type­kit is pretty fast.

Here is how I think this should have been done: each time you mod­ify your font kit, you get a new URL to use (con­tain­ing the ver­sion of the font kit for ex­am­ple). This re­source and the as­so­ci­ated fonts (whose URL is also ver­sioned) are re­quested to be cached for sev­eral days. As a side­note, this also en­ables to mod­ify a kit for your de­vel­op­ment en­vi­ron­ment with­out mod­i­fy­ing the kit for your pro­duc­tion site.

I sus­pect Type­kit did not go this way to track kit us­age more ac­cu­rately and en­force the ap­pro­pri­ate pric­ing. Hav­ing mul­ti­ple ver­sions of the same kit would also al­low us to use more fonts that we are paying for.

Up­date (2011-11)

Type­kit sup­port knows the prob­lem and is work­ing on it:

You’ve iden­ti­fied a small bug in our CDN provider that we’re work­ing with them to fix. Hope­fully I can give an ex­pla­na­tion of what’s happening.

The CDN edge servers have a cache of re­cently served kits on them. Any re­quest that is served from that cache will be cor­rectly Gzipped and han­dle ETags. Un­for­tu­nately, if the con­tent isn’t al­ready in cache and needs to be fetched from the mas­ter ori­gin server then the re­quest won’t be gzipped cor­rectly which has the side ef­fect of break­ing ETags.

[…]

We are work­ing to on get­ting this bug fixed, but any change to a glob­ally dis­trib­uted CDN will take some time. We’re also work­ing on hav­ing our con­tent cached longer than 5 min­utes whilst still al­low­ing peo­ple to quickly up­date their site.

Up­date (2012-03)

To avoid block­ing page load­ing if Type­kit is slow, you can load it asyn­chronously with yepnope.js. You will get some FOUT instead.

Conclusion#

I have mixed feel­ings about Type­kit. While the dif­fi­culty to test fonts and the lack of lan­guage-re­lated sub­sets are an­noy­ing, I have been able to work around them. How­ever, the caching prob­lem is more an­noy­ing. I am still con­sid­er­ing go­ing back to Google Web Fonts just be­cause of this.