Google字体:语言选择不起作用

时间:2016-11-07 10:31:52

标签: fonts webfonts google-font-api

我在很多客户网站上使用Google字体Roboto

当您在Google字体上自定义字体时,您可以选择多种语言选项:

  • 希腊语(由Roboto支持)
  • 拉丁语扩展(由Roboto支持)
  • 西里尔语(由Roboto支持)
  • 越南语(由Roboto支持)
  • Cyrillic Extended(由Roboto支持)
  • 希腊语扩展(由Roboto支持)
  • 拉丁语(由所有字体支持)

对于这些客户端网站,我只需要使用拉丁语言,而不需要加载任何其他语言。

但是,当我加载此字体并定义拉丁语时,您可以看到所有其他语言也加载在生成的样式表中:

https://fonts.googleapis.com/css?family=Roboto:300&subset=latin

/* cyrillic-ext */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/0eC6fl06luXEYWpBSJvXCBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
/* cyrillic */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* greek-ext */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/-L14Jk06m6pUHB-5mXQQnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+1F00-1FFF;
}
/* greek */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/I3S1wsgSg9YCurV6PUkTORJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0370-03FF;
}
/* vietnamese */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/NYDWBdD4gIq26G5XYbHsFBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Pru33qjShpZSmG3z6VYwnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
  unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 300;
  src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}

我的理解是,定义&subset=latin只加载该语言,为什么所有语言都加载到这里?

1 个答案:

答案 0 :(得分:1)

我正在this answer复制Daryl Teo,因为他似乎为您的问题提供了正确答案。

  

诀窍在于优化:

     

unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;

     

有了这个,浏览器知道是否需要下载字体,具体取决于它刚刚加载到html中的字符。

在此处查看哪些浏览器具有full support for this

早期的浏览器,例如Firefox< 44和Safari< 10,忽略(部分)规范,或者需要启用它,因此Google Fonts必须为它提供最小的字体 - 面部规范。