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

问题描述 投票:6回答:1

我在很多客户网站上使用Google Font 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只加载那种语言,那么为什么所有的语言都被加载到这里?

fonts webfonts google-font-api
1个回答
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必须为其提供最小的字体 - 面部规范。

© www.soinside.com 2019 - 2024. All rights reserved.