从缓存中加载Js文件

在我进行AJAX调用并用$("body").html(this.responseText.match(/<\s*body.*>[\s\S]*<\s*\/body\s*>/ig).join(""));更改正文内容后,我的head元素中的js文件没有重新加载。因此,我必须将所有这些js文件都包含在body元素的底部。问题是,每次我进行AJAX调用时,它都会从服务器而不是从缓存中下载所有JS文件,这会对Internet流量产生不良影响。如何从浏览器缓存中获取js文件?

我的ajax方法:

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);

}

我的响应标题:

Request URL:http://localhost:8000/static/js/switchMode.js?v08112019.104821&_=1573463871279
Request method:GET
Remote address:127.0.0.1:8000
Status code:
200
Version:HTTP/1.1
Referrer Policy:no-referrer-when-downgrade

Response headers (200 B)    
Raw headers
Content-Length  
3769
Content-Type    
application/javascript
Date    
Mon,11 Nov 2019 09:18:14 GMT
Last-Modified   
Fri,08 Nov 2019 08:48:21 GMT
Server  
WSGIServer/0.2 CPython/3.5.2
Request headers (757 B) 
Raw headers
accept  
text/javascript,application/j…ion/x-ecmascript,*/*; q=0.01
accept-Encoding 
gzip,deflate
accept-Language 
en-US,en;q=0.5
Connection  
keep-alive
Cookie  
csrftoken=c2QFtU6qkpzWJpqvqRXN…qid=3; show_btn=false; _gat=1
Host    
localhost:8000
Referer 
http://localhost:8000/exam/e5d…bd5713f44d1b90538b579539509/6/
User-Agent  
Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/70.0
X-Requested-With    
XMLHttpRequest
xlongfei 回答:从缓存中加载Js文件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3126046.html

大家都在问