javascript - 如果我对当前正在下载的文件进行 XMLHttpRequest 会怎样?

标签 javascript html ajax prefetch

我正在尝试逐步增强 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/

相关文章:

ajax - 无法访问 Ajax JSON 数据对象

javascript - 使用 jspm 配置运行 typescript angular2 应用程序的页面加载错误

javascript - 警报输入类型数字的值

javascript - relatedObject 属性的用途

html - <code> vs <pre> vs <samp> 用于内联和 block 代码片段

javascript - 调整由 ng-if 指令动态生成的 <div> 标签的高度

javascript - 从 Java android 调用 AngularJs Controller 函数

javascript - 我需要打开一个页面,然后在一段时间后重新加载它

jquery - 在 Ajax 应用程序中将数据从 servlet 传递到 javascript 代码?

asp.net - 401 向 web api 发送 ajax 请求时未经授权