Tigt
Tigt

Reputation: 1497

What happens if I XMLHttpRequest for a currently downloading file?

I'm trying to progressively enhance links in the PJAX style. I was planning on layering it on top of some regular prefetch <link>s:

<link rel="prefetch" href="next.html"/>

If the browser has already downloaded next.html, the PJAX request should just hit the cache, and no harm done. But of course, since the actual fetching of prefetch links is completely up to the browser, I can't know when that will be.

I'd hate to subject users to a double download, so I've considered just taking the <link> off. But browsers have started preloading/rendering on the <link rel="next"/> tag too, which complicates things.

If XMLHttpRequest hits an "in-flight" download, what kind of browser behaviors can I expect? I'm trying to do my own research, but it's fraught with race conditions and other nastiness.

Upvotes: 2

Views: 152

Answers (1)

Oleg
Oleg

Reputation: 23297

From the MDN FAQ:

What happens if I click on a link while something is being prefetched?
When the user clicks on a link, or initiates any kind of page load, link prefetching will stop and any prefetch hints will be discarded. If a prefetched document is partially downloaded, then the partial document will still be stored in the cache provided the server sent an "Accept-Ranges: bytes" response header. This header is typically generated by webservers when serving up static content. When the user visits a prefetched document for real, the remaining portion of the document will be fetched using a HTTP byte-range request.

Upvotes: 1

Related Questions