Reputation: 27
I'm using XMLHttpRequest()
to load some js file. Is the file cached by the browser using the following code?
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);
Upvotes: 0
Views: 805
Reputation: 944064
Normal rules for caching apply when you use XMLHttpRequest.
The file may or may not be cached depending on the HTTP headers in the response.
Upvotes: 1