Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
How to change global variable content in javascript programable from json files?

I have a web page where content is displayed depend of week day and selected hour. Visitor can change day and hour and want to see content on Leaflet map. Each day contain about 100 js files with size about 900k each. I don't want to load all files for 7 days (7 * 100 = 700 * 900k = 615MB) Particular day and hour has only one file with 900kb size and should be changed/loaded when visitor will change it. Each file has name like : day_time.json; i.e. day0_0900.js, day1_1200.js, day5_1800.js I tried declare global variable (var mydailydata;) at the beginning of global js file then use functions :

function loadScript(url, callback)
{
   var head = document.getElementsByTagName('head')[0];
   var script = document.createElement('script');
   script.type = 'text/javascript';
   script.src = url;
   script.onreadystatechange = callback;
   script.onload = callback;
   head.appendChild(script);
}

var myPrettyCode = function() {
    console.log("Loaded");
};



function loadjscssfile(filename, filetype){
    if (filetype=="js"){ //if filename is a external JavaScript file
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

and load js file into head or body via :

loadjscssfile("data/day0_0900.js", "js");

and change URL with function responsible for changing day & time. I can see <script type="text/javascript" src="data/day0_0900.js"></script> in source code but content is not visible on web page.

at the beginning of data file I have : var mydata = [{....}] and when I enter <script type="text/javascript" src="data/day0_0900.js"></script> statically into section of index file, content is displayed but only for particular day and time.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!