gpt4 book ai didi

javascript - 文件是否使用 XMLHttpRequest() 进行缓存

转载 作者:行者123 更新时间:2023-12-03 02:42:48 27 4
gpt4 key购买 nike

我正在使用 XMLHttpRequest() 加载一些 js 文件。浏览器是否使用以下代码缓存文件?

var xhr = new XMLHttpRequest();
xhr.open("get", "example.js", true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
var script = document.createElement("script");
script.type = "text/javascript";
script.text = xhr.responseText;
document.body.appendChild(script);
}
}
};
xhr.send(null);

最佳答案

当您使用 XMLHttpRequest 时,适用正常的缓存规则。

文件可能会也可能不会被缓存,具体取决于响应中的 HTTP header 。

关于javascript - 文件是否使用 XMLHttpRequest() 进行缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48249744/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com