After I make an AJAX call and i change the body content with $("body").html(this.responseText.match(/<\s*body.*>[\s\S]*<\s*\/body\s*>/ig).join(""));
my js files in my head
element does not reload. So I had to include all these js files in the bottom of the body
element. The problem is that each time when I make an AJAX call it downloads all JS files from the server not from cache, and it has a bad effect on internet traffic. How can I get the js files from browser cache memory?
My ajax method:
function AJAXFormPost(data, formAction) {
var httpRequest = new XMLHttpRequest();
var formData = new FormData();
Object.keys(data).forEach(function(key) {
formData.append(key, data[key]);
});
httpRequest.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// replace body content
$("body").html(this.responseText.match(/<\s*body.*>[\s\S]*<\s*\/body\s*>/ig).join(""));
// Update url
test_mode = window.location.href.split('/')[3];
question_number = document.getElementById("lblNrCrt").textContent;
pageUrl = "/" + test_mode + "/" + test_uuid + "/" + question_number + "/";
window.history.pushState('', '', pageUrl);
}
};
httpRequest.open("post", formAction);
httpRequest.send(formData);
}