I am trying to make this blog completely tracker-free. To achieve that, I need to avoid fetching resources from any third-party servers, such as Google Web Fonts. There are some articles discussing how to download the different formats required for cross-browser compatibility, but manually downloading a series of files using different browsers isn’t what I had in mind – I’m a computer science student after all. So I toolchained it. Meet the Google Web Font download script (requires Bash 4.x), available from its new home on GitHub.
The script provides a command line interface to specify the fonts to be downloaded as given in the
of the URL generated by Google’s Web Font service. It uses
curl to emulate different user agents (since the CSS file
returned by Google’s setup depends on it), downloads the font files into the current directory and generates a CSS file
that provides the font definition using Fontspring’s Bulletproof @Font-face Syntax. The generated file is
a drop-in replacement for the file previously fetched from Google’s servers. Since it includes all font files and
doesn’t depend on the user agent it might not be as efficient as the original, though (I have not actually verified
this). If efficiency is key for you, you may want to limit the number of formats you provide, because
WOFF support is pretty widespread in modern browsers.
Don’t forget to configure the MIME types for the font files on your web server.
- Version 1.2, 2015-06-13
- Add getopt interface
- Support font subsets, modifications by Thomas Papamichail
- Version 1.1.1, 2015-04-09
- Switch user agent to IE 8 for WOFF to fix problems
- Version 1.1, 2014-06-21
- Remove colons and spaces from file names for Windows compatibility, patch from campino2k
- Add check for Bash version, 4.x is required
- Correctly handle fonts without a local PostScript name
format('truetype')in CSS output
- Add license header and comments
- Added sed extended regex flag detection
- Version 1.0, 2014-03-19