简体   繁体   English

谷歌网络字体下载备份?

[英]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? 像我们怎么做window.jquery检查google jquery cdn是否关闭并提供替代文件?

You can simply specify a web font version installed on your own server as the second option, eg 您可以简单地指定安装在您自己的服务器上的Web字体版本作为第二个选项,例如

<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 . 在示例中,我使用了FontSquirrel @ font-face生成器生成的名称

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. 这样,浏览器将首先尝试从Google网站获取字体文件,如果由于某种原因失败,它将从您的服务器获取字体文件。

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.) (很难看到它;但是从用户设备到Google网站的连接可能会被破坏,即使您的网站连接正常。)

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. 这将使用Google webfont Skranji,如果它不可用,它将把它撞到Verdana,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM