简体   繁体   中英

HTTP2 Push XMLHttpRequest Cache Miss in Chrome

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?

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"?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM