1

I'm using google fonts, and am checking to see how large my WOFF2 file is in fact going to be.

So to test, I loaded a font via their API http://fonts.googleapis.com/css?family=PT+Sans+Narrow&text=hello and then looked at the output

@font-face {
  font-family: 'PT Sans Narrow';
  font-style: normal;
  font-weight: 400;
  src: local('PT Sans Narrow'), local('PTSans-Narrow'), url(http://fonts.gstatic.com/l/font?kit=UyYrYy3ltEffJV9QueSi4VubgSqbO8GPta82DSsWGmo) format('woff2');
}

And then I physically downloaded the file http://fonts.gstatic.com/s/ptsansnarrow/v7/UyYrYy3ltEffJV9QueSi4UU-p1xzoRgkupcXIqgYFBc.woff2

I was shocked to see that it is apparently over 2kb.

How can this be? it's just the glyphs for "hello".

To compare, I loaded the entire font (all glyphs, using the same technique, and that gave me a 37kb file.

Am I just naive to think custom fonts should be low file size? Or is there a way to get this compressed more? At this rate, I'm almost thinking, loading an SVG is better...

5
  • That is pretty small, but when I converted that font and stripped out all the extra garbage, the glyphs for "Hello" took 812 bytes. Commented May 15, 2015 at 19:42
  • 1
    of course a large part of that "garbage" is required OpenType data without which the font will fail validation before it's deemed a real font file. Commented May 15, 2015 at 19:43
  • @Mike'Pomax'Kamermans Not sure what you would consider "a real font file". I consider it one that displays text in the font that I want. Which it does just fine. I just removed the unused glyphs and the kerning stuff that wasn't necessary for "Hello". Commented May 15, 2015 at 19:47
  • Not sure I follow. OpenType fonts have an authoritative spec, so it's not an opentype font unless it fulfills that spec, and in websetting, it'll also have to pass OTS validation since that's what Chrome and Firefox use to make sure the data you're loading is actually a font. You can strip a fair bit of data from them (see my answer) but depending on what you remove, you might be turning it into "this is no longer a real font, just a bunch of bytes on disk". TTX and WOFF2 compression will help, but there's still a floor on the filesize. Commented May 15, 2015 at 19:51
  • Sorry, I didn't mean I took out all the stuff necessary to render it. I just removed the unused glyhs and all the kerning information (since no kerning rules applied to 'Hello'). I'm also not a font expert so I had to convert the .woff2 to ttf then to svg, then I editted it, then converted it back to woff2 again. Commented May 15, 2015 at 20:04

1 Answer 1

3

What do you mean "it's just the glyphs for hello"? Because it's not:

enter image description here

Unless you want to dive into how OpenType really works, and how to bytesnipe it to a tiny tiny thing, 2kb makes a lot of sense for something that's encoding five vector images, plus all the metadata required for opentype engines to accept the font's internal organisation on all platforms.

3
  • @Robert McKee Bytesniping, lol. I like the expression... I'm confused about your comment above, where you assume that kerning stuff isn't necesary to display hello. IMHO, it very much is the purpose of a custom font to define kerning, in order to render words as intended by the font designer, for readability and aesthetic purposes. Simply displaying 5 glyphs next to another does a font not make.
    – tim
    Commented May 15, 2015 at 21:38
  • Compared to a SVG, I am still struggling to see why a 5-letter word in custom font has to be 2kb of data, spec or not.
    – tim
    Commented May 15, 2015 at 21:39
  • @tim I never said anything about kerning not being necessary? If you're commenting to Robert, better to do that as a reply where he made it. As for why you need 2kb, have a look at that "it's not" link ("what do the numbers tell us" section), it shows you all the overhead a font uses just for seven letters (about 1300bytes, of which less than 300 are the glyphs), and that's using the CFF flavour of opentype (which is typically smaller than the truetype version) with almost no text for things like font and glyph names. With those specified "as normal", it'd easily grow to 2500 or more bytes. Commented May 15, 2015 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.