Search code examples
angulartomcatcdnhttp2

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


Currently the index.html file of my angular app is generated from a tomcat server(Apache Coyete). The index.html file consists js, css and images pointing to our own CDN. Example:

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

Suppose I want to server push 'https://mc1.mcdn.in/main.adjhf432hjh23k44.js' file. Is it possible to server push a CDN link? Also, Is there any way to server push all the files that match a pattern? like main.{hash}.js polyfills.{hash}.js etc


Solution

  • You can only push items from a connection which is authorative for the domain of the resource. 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

    So if the index file is also served via the CDN, then you can push the static assets on that connection. But if the index.html is served from a separate domain and IP address to the assets then they cannot be pushed.

    You can use the 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.