Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to add a Javascript file from the server to the LocalStorage and site header. i try this code but some things wrong??


i have external script , i want only One time download script file to speed up site load. title attribute download script file for each load page

What I have tried:

var s = document.createElement("script");
s.type = "text/javascript";
s.src = localStorage.theImage;
s.title = "myJavaScript";
$("head").append(s);

function addScript() {

    var csvRequest = new Request({
        url: "splitNumber.js",
        onSuccess: function (response) {
            var responseFile = response;
            var file = responseFile;
            var reader = new FileReader();

            reader.onload = function (e) {
                var s = document.createElement("script");
                s.type = "text/javascript";
                s.src = reader.result;
                localStorage.theImage = reader.result;
                $("head").append(s);
            }

            reader.readAsDataURL(file);//attempts to read the file in question.
        });
    }
}
Posted
Comments
F-ES Sitecore 13-Aug-18 5:46am    
The browser will deal with js file caching itself, no need for you to handle this yourself.
Member 13292615 13-Aug-18 9:11am    
thanks for Reply, but i like complete my code for better learning, can you help my to finish the method ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900