Remove unused characters from fonts to save on size

To render code blocks on this blog I use Prism. The header has two symbols that use Font Awesome, one to denote that it's a code block and another for the copy icon:

# Look at the top left and top right

This font file was 160kB though, even though I only needed two glyphs. You can shrink font files using pyftsubset 1 brew install fonttools if you don't have it, and if you don't have brew then the GitHub has install instructions. to just the Unicode codepoints you need. In this case the command got the file from 160kB down to 680 bytes, a 99.5% savings:

pyftsubset fa-solid-900.woff2 --unicodes="U+f328,U+f121" --flavor="woff2" --output-file="fa-solid-900-subset.woff2"

I also used this for the custom handshake emoji snippet post to shrink the fallback .ttf file from 42MB down to 1.1MB.

pyftsubset AppleColorEmoji.ttf --unicodes="U+1F1E6,U+1F1E8,U+1F1F3,U+1F1F7,U+1F1F8,U+1F1FA,U+1F3FB,U+1F3FF,U+1F468,U+1F469,U+1F48B,U+1F91D,U+1FAF1,U+1FAF2,U+200D,U+2764,U+FE0F" --output-file="AppleColorEmoji-subset.ttf"

And finally I used it for shrinking Glyphicons Halflings 2 One of these days I'll gut the Bootstrap dependency from this blog, but today is not that day. from 23kB to 2kB (and 1kB for .woff2). This also shows how it can be used to convert between font types too. 3 I dropped .eot, .svg, and .ttf support with this change: it's time for WOFF.

pyftsubset glyphicons-halflings-regular.woff --unicodes="U+E033,U+E056,U+E003" --flavor="woff" --output-file="glyphicons-halflings-regular-subset.woff"
pyftsubset glyphicons-halflings-regular.woff --unicodes="U+E033,U+E056,U+E003" --flavor="woff2" --output-file="glyphicons-halflings-regular-subset.woff2"

  1. brew install fonttools if you don't have it, and if you don't have brew then the GitHub has install instructions. ↩︎

  2. One of these days I'll gut the Bootstrap dependency from this blog, but today is not that day. ↩︎

  3. I dropped .eot, .svg, and .ttf support with this change: it's time for WOFF↩︎