谷歌字体:语言选择无法正常工作

7
我在很多客户网站上使用Google字体Roboto
当您在Google字体上自定义字体时,您可以选择许多语言选项:
- 希腊语(由Roboto支持) - 拉丁扩展(由Roboto支持) - 西里尔文(由Roboto支持) - 越南语(由Roboto支持) - 扩展西里尔文(由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个回答

3
我正在复制Daryl Teo这个答案,因为他似乎提供了您问题的正确答案。
诀窍在于这个优化: unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
有了这个,浏览器知道它是否需要下载字体,这取决于它刚刚在HTML中加载的字符。
请看这里的浏览器完全支持此功能
早期的浏览器(例如 Firefox <44 和 Safari <10)忽略了规范的(部分)内容,或者需要启用它,因此 Google Fonts 必须提供一个最小的 font-face 规范。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接