fontsgoogle-font-api

How to host google web fonts on my own server?


I need to use some google fonts on an intranet application. The clients may or may not have internet connection. Reading the license terms, it appears that its legally allowed.


Solution

  • Please keep in mind that my answer has aged a lot.

    There are other more technically sophisticated answers below, e.g.:

    so don't let the fact that this is the currently accepted answer give you the impression that this is still the best one.


    You can also now also download google's entire font set via on github at their google/font repository. They also provide a ~1GB zip snapshot of their fonts.


    You first download your font selection as a zipped package, providing you with a bunch of true type fonts. Copy them somewhere public, somewhere you can link to from your css.

    On the google webfont download page, you'll find a include link like so:

    http://fonts.googleapis.com/css?family=Cantarell:400,700,400italic,700italic|Candal
    

    It links to a CSS defining the fonts via a bunch of @font-face defintions.

    Open it in a browser to copy and paste them into your own CSS and modify the urls to include the right font file and format types.

    So this:

        @font-face {
          font-family: 'Cantarell';
          font-style: normal;
          font-weight: 700;
          src: local('Cantarell Bold'), local('Cantarell-Bold'), url(http://themes.googleusercontent.com/static/fonts/cantarell/v3/Yir4ZDsCn4g1kWopdg-ehHhCUOGz7vYGh680lGh-uXM.woff) format('woff');
        }
    

    becomes this:

        /* Your local CSS File */
        @font-face {
            font-family: 'Cantarell';
            font-style: normal;
            font-weight: 700;
            src: local('Cantarell Bold'), local('Cantarell-Bold'), url(../font/Cantarell-Bold.ttf) format('truetype');
        }
    

    As you can see, a downside of hosting the fonts on your own system this way is, that you restrict yourself to the true type format, whilst the google webfont service determines by the accessing device which formats will be transmitted.

    Furthermore, I had to add a .htaccess file to my the directory holding the fonts containing mime types to avoid errors from popping up in Chrome Dev Tools.

    For this solution, only true type is needed, but defining more does not hurt when you want to include different fonts as well, like font-awesome.

    #.htaccess
    AddType application/vnd.ms-fontobject .eot
    AddType font/ttf .ttf
    AddType font/otf .otf
    AddType application/x-font-woff .woff