为什么下载的是 Woff 文件而不是 Woff2?谷歌字体/NextJS

Vot*_*ike 5 fonts font-face next.js

NextJS对 Google Fonts 进行了字体优化,它从 Google Fonts(使用 Chrome 和 IE 用户代理)下载字体定义,并将该定义放置在 DOM 的头部。这是为了加快所需字体的下载速度。

当使用具有单独指定权重的 URL(例如https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;700&display=swap )时, font-weight 的字体系列定义是单个数字。EG 700。在使用 Chrome 的 Vanilla NextJS 12 应用程序中,这会正确下载单个 Woff2 文件。

当使用具有一系列指定权重的 URL(例如https://fonts.googleapis.com/css2?family=Open+Sans:wght@300..700&display=swap )时, font-weight 的字体系列定义有两个数字。EG 300 700。在使用 Chrome 的 Vanilla NextJS 12 应用程序中,这会下载一个 Woff2 文件以及每个字体粗细的 Woff 文件。
如果我编辑NextJS 优化脚本以避免 Next 使用 IE 用户代理预下载字体定义......我正确地只下载了一个 Woff2 文件。

为什么?这是 Chrome 中的错误吗?或者NextJS?

我假设由于字体粗细是用 2 个数字指定的,Chrome 会选择从 IE 用户代理定义的更精确定义的字体系列,因此下载 Woff 字体。但如果是这样的话……为什么?

这是最终的字体定义:

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300;
    font-stretch: normal;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsiH0C4k.woff) format('woff')
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 400;
    font-stretch: normal;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsjZ0C4k.woff) format('woff')
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 500;
    font-stretch: normal;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsjr0C4k.woff) format('woff')
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 600;
    font-stretch: normal;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsgH1y4k.woff) format('woff')
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 700;
    font-stretch: normal;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsg-1y4k.woff) format('woff')
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSKmu0SC55K5gw.woff2) format('woff2');
    unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSumu0SC55K5gw.woff2) format('woff2');
    unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSOmu0SC55K5gw.woff2) format('woff2');
    unicode-range: U+1F00-1FFF
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSymu0SC55K5gw.woff2) format('woff2');
    unicode-range: U+0370-03FF
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTS2mu0SC55K5gw.woff2) format('woff2');
    unicode-range: U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSCmu0SC55K5gw.woff2) format('woff2');
    unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+1EA0-1EF9, U+20AB
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTSGmu0SC55K5gw.woff2) format('woff2');
    unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF
}

@font-face {
    font-family: 'Open Sans';
    font-style: normal;
    font-weight: 300 700;
    font-stretch: 100%;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/opensans/v29/memvYaGs126MiZpBA-UvWbX2vVnXBbObj2OVTS-mu0SC55I.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD
}
Run Code Online (Sandbox Code Playgroud)