Script to download and host google web fonts and generate css: best-served-local

Local Google web font hosting made easy, controllable and automated

The bash script best-served-local makes downloading and self-hosting a Google web font as easy as running the following command in a terminal:

<code>bash <(wget -q -O - "" >dev/null) "Roboto:100,900"</code>
bash <(wget -q -O - "" >dev/null) "Roboto:100,900"

This will download the appropriate font files (like Roboto_Bold_v15_latin_700.woff) to a local temporary directory and display the following valid css3 in the terminal:

@font-face {
    font-family: 'Roboto Bold';
   local('Roboto Bold'), local('Roboto-Bold'), 
   url('Roboto_Bold_v15_latin_700.woff2') format('woff2'),
   url('Roboto_Bold_v15_latin_700.woff') format('woff');
    font-style:  normal;
    font-weight: 700;

Specifying a few extra options fully automates your desired usage scenario:

<code>bash <(wget -q -O - "") \ 
 --incss-fontpath /static/fonts \ 
 --outputfile /var/www/ \ 
 --fontdirectory /var/www/ --overwrite \ 
 --formats superprogressive \ 
 --subsets latin-ext \ "Open Sans:300,400,700" "Roboto:100,100italic,regular,italic,900"</code>

Apart from bash version 4, this script only depends on curl (it’s not tested on OSX yet).

Getting and running the script

The script can be cloned or forked from its gitlab repository, downloaded, or started straight from the web like showed above (although some would advise against that).

To display all commandline arguments, run the script with the --help (or -h) argument.

See the README file for detailed usage information.

Happy Google-free hosting!

Leave a Reply

Your email address will not be published. Required fields are marked *