我们可以使用 HTTP 2 服务器推送存在于其他 CDN 中的资产吗?

Can we HTTP 2 server push assets present in other CDN?

目前,我的 angular 应用程序的 index.html 文件是从 tomcat 服务器 (Apache Coyete) 生成的。 index.html文件由js、css和图片组成,指向我们自己的CDN。示例:

<script src="https://mc1.mcdn.in/main.adjhf432hjh23k44.js" />

假设我想服务器推送“https://mc1.mcdn.in/main.adjhf432hjh23k44.js”文件。是否可以服务器推送 CDN link?另外,有没有办法让服务器推送所有匹配模式的文件?像 main.{hash}.js polyfills.{hash}.js 等

您只能从对资源域具有权威性的连接中推送项目。 From the HTTP/2 specification:

A client MUST treat a PUSH_PROMISE for which the server is not authoritative as a stream error... of type PROTOCOL_ERROR

因此,如果索引文件也通过 CDN 提供,那么您可以在该连接上推送静态资产。但是,如果 index.html 从单独的域和 IP 地址向资产提供服务,则无法推送它们。

您可以使用 preload resource hint to prioritise items (particularly late discovered resources) which many advise as four enough, given HTTP/2 push’s complexities and browser support.