The HTML5 Boilerplate uses a script for loading a local copy of jQuery if, for whatever reason, the Google CDN version fails to load:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
Is it possible to do something like this with Google Web Fonts? Meaning: if the remote font fails to load, use a local copy of the font stored on your server instead.
To host Google Fonts locally, you need to upload all the font files you want to use to your server and also add the corresponding @font-face rules to your CSS. You can do all that manually, but there's a handy open-source tool called Google Web Fonts Helper that automates the process for you.
The actual load time of your website will suffer if you host Google Fonts locally. Google uses the best-in-class web performance technologies to serve fonts.
A fallback font is a reserve typeface containing symbols for as many Unicode characters as possible. When a display system encounters a character that is not part of the repertoire of any of the other available fonts, a symbol from a fallback font is used instead.
I've just had this problem and thought of a solution just after I came to this page:
@import url(http://fonts.googleapis.com/css?family=Ubuntu:400,400italic,700,700italic);
@font-face {
font-family: "UbuntuFallback";
font-style: normal;
font-weight: normal;
src: url("/webfonts/ubuntu/ubuntu-webfont.eot?#iefix") format("embedded-opentype"), url("/webfonts/ubuntu/ubuntu-webfont.woff") format("woff"), url("/webfonts/ubuntu/ubuntu-webfont.ttf") format("truetype");
}
@font-face {
font-family: "UbuntuFallback";
font-style: normal;
font-weight: bold;
src: url("/webfonts/ubuntu/ubuntu-bold-webfont.eot?#iefix") format("embedded-opentype"), url("/webfonts/ubuntu/ubuntu-bold-webfont.woff") format("woff"), url("/webfonts/ubuntu/ubuntu-bold-webfont.ttf") format("truetype");
}
@font-face {
font-family: "UbuntuFallback";
font-style: italic;
font-weight: normal;
src: url("/webfonts/ubuntu/ubuntu-italic-webfont.eot?#iefix") format("embedded-opentype"), url("/webfonts/ubuntu/ubuntu-italic-webfont.woff") format("woff"), url("/webfonts/ubuntu/ubuntu-italic-webfont.ttf") format("truetype");
}
@font-face {
font-family: "UbuntuFallback";
font-style: italic;
font-weight: bold;
src: url("/webfonts/ubuntu/ubuntu-bolditalic-webfont.eot?#iefix") format("embedded-opentype"), url("/webfonts/ubuntu/ubuntu-bolditalic-webfont.woff") format("woff"), url("/webfonts/ubuntu/ubuntu-bolditalic-webfont.ttf") format("truetype");
}
body
{
font-family: Ubuntu, UbuntuFallback, Tahoma, Sans-Serif;
}
So I wanted to use the Ubuntu font, however our website is run on a localhost and won't necessarily be connected to the internet. I created some @font-face declarations to the Ubuntu font, called it something else ("UbuntuFallback") and just put it in the font-family style list.
Voilá!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With