我正在尝试逐步增强 PJAX 中的链接风格。我正计划将它分层放置在一些常规预取之上 <link>
小号:
<link rel="prefetch" href="next.html"/>
如果浏览器已经下载next.html
,PJAX 请求应该直接命中缓存,不会造成任何伤害。但当然,由于预取链接的实际提取完全取决于浏览器,我不知道那会是什么时候。
我不想让用户接受双重下载,所以我考虑过只使用 <link>
离开。 But browsers have started preloading/rendering on the <link rel="next"/>
tag too ,这让事情变得复杂。
如果 XMLHttpRequest 命中“飞行中”下载,我可以期待什么样的浏览器行为?我正在尝试进行自己的研究,但它充满了竞争条件和其他麻烦。
最佳答案
来自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.
关于javascript - 如果我对当前正在下载的文件进行 XMLHttpRequest 会怎样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28449885/