HTTP2 Push XMLHttpRequest Cache Miss in Chrome

2019-02-19 14:56发布

问题:

I'm setting the Link header to preload an XHR request that happens on load.

Link: </images/project_icon.png>; rel=preload; as=image,</db/xhr_stuff>; rel=preload

Chrome 57.0 preloads and uses the /images/project_icon.png just fine but it preloads /db/xhr_stuff and then misses the copy it just retrieved and loads it a second time after the DOM completely loads. The request headers are identical except the one later one initiated by the xhr has x-requested-with:XMLHttpRequest set. The only other difference between the requests is the one initiated by the link header shows up as Type: json and the second Type: xhr in the Developer Tools.

According to the docs for XHR request, you just omit the as= attribute.

What is missing to get a cache hit?

回答1:

If you don't provide the "as=" attribute when you push it will be ignored by the page and loaded again.

According to the docs for XHR request, you just omit the as= attribute.

Where do you see this? What "docs"?