未使用推送的HTTP2 Web字体。

10

我在 HTTP2 响应中发送了一个 Link 预加载头,就像这个:

Link: </assets/script/main.js?h=1795387974>; rel=preload; as=script, </assets/font/sourcesanspro_regular.woff2>; rel=preload; as=font

脚本、样式和图像不会引起任何问题 - 它们被推送并使用。但字体被推送后会再次请求/获取,然后Chromium控制台会抱怨:

资源https://example.com/assets/font/sourcesanspro_regular.woff2使用链接预加载进行了预加载,但从窗口的加载事件开始几秒钟内未被使用。请确保它不是为了无用而被预加载。

这是所提到字体的响应标头。

推送:

accept-ranges:bytes
cache-control:max-age=5184000, public
content-length:16892
content-type:application/octet-stream
date:Mon, 25 Sep 2017 09:22:05 GMT
last-modified:Mon, 18 Sep 2017 14:33:31 GMT
pragma:public
status:200
x-content-type-options:nosniff
x-frame-options:SAMEORIGIN
x-http2-push:pushed
x-xss-protection:1; mode=block

推送后请求:

accept-ranges:bytes
cache-control:max-age=5184000, public
content-length:16892
content-type:application/octet-stream
date:Mon, 25 Sep 2017 09:22:05 GMT
last-modified:Mon, 18 Sep 2017 14:33:31 GMT
pragma:public
status:200
x-content-type-options:nosniff
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block

我做错了什么?

1个回答

6

1
我认为你的解决方案中有一个错别字。在crossorigin之前需要加上;。这是一个没有值的属性。 - cherouvim
正确!已修复。 - Barry Pollard

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