Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google web fonts down backup?

I am wondering if there is a way to go okay, google web fonts is down use this as the font source instead? Something like how we do window.jquery check to see if google jquery cdn is down and serve an alternative file?

like image 439
Steven Avatar asked Feb 17 '23 09:02

Steven


2 Answers

You can simply specify a web font version installed on your own server as the second option, e.g.

<link href='https://fonts.googleapisx.com/css?family=Cantarell' rel='stylesheet'>
<style>
@font-face {
    font-family: 'cantarellregular';
    src: url('cantarell-regular-webfont.eot');
    src: url('cantarell-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('cantarell-regular-webfont.woff') format('woff'),
         url('cantarell-regular-webfont.ttf') format('truetype'),
         url('cantarell-regular-webfont.svg#cantarellregular') format('svg');
    font-weight: normal;
    font-style: normal;
}
body { font-family: Cantarell, cantarellregular; }
</style>

You will need a different name for the font family in your server; in the example I have used the name produced by FontSquirrel @font-face generator.

This way, the browser will try to fetch the font file first from the Google site, and if this fails for some reason, it will fetch the font file from your server.

I wonder why you don’t simply use the font from your own server, if you are worried about Google site being down. (It would be rare to see it down; but the connection from user’s device to Google site might be broken, even though connection to your site is OK.)

like image 131
Jukka K. Korpela Avatar answered Feb 28 '23 05:02

Jukka K. Korpela


You can list multiple font families and they would be displayed in that order. For example

font-family: 'Skranji', cursive, Verdana, Geneva, sans-serif;

This will use the Google webfont Skranji, if that's not available it will bump it to Verdana, and so on.

like image 21
Ionko Gueorguiev Avatar answered Feb 28 '23 03:02

Ionko Gueorguiev