Q: What is the best replacement to setTimeout for window to be fully loaded? J is an object with various functions. 
Functions u, t and z should be run, when g, m and c are fully loaded in the window (for both web and mobile), which takes few milli-hundred secs for servers to respond. 
What would be the fastest or best way to replace the setTimeout function (800 ms)? 
Thanks a million, 
M
J.o({p:'/dir/file-1.txt'});
J.e({
    g:'/dir/file-2.txt',
    m:'/dir/prefix-',
    c:'/dir/prefix-string.txt'
}); // a function that gets a few files with texts or JSON objects
setTimeout(function(){ 
    J.u({g: window['g'],m: window['m'],c: window['c']}); // a function to be run after loading three JSON objects in window
    J.t(window['p'],{t:"two"}); // a function to be run after loading another large JSON object
    J.z({});
}, 800);




// J.o function 
o:function(z){
    var g,h,x=[];

    Object.keys(z).forEach(function(a,b,c){
        window[a]=null;
        x[b]=new XMLHttpRequest();
        url=window.location.origin.concat('/',z[a.toString()]);
        x[b].open("GET",url,true);
        x[b].onreadystatechange=function (z){
            if(x[b].readyState===4){
                if(x[b].status===200 || x[b].status==0){
                    window[a]=x[b].responseText;
                }
            }
        }
        x[b].send();
     });
}



// J.e function for styles
e:function(z){
    var w,y,e,ar,x=[];
    Object.keys(z).forEach(function(a,b,c){
        window[a]=null;
        x[a]=new XMLHttpRequest();
        if(a=='m'){
            w=window.innerWidth; /*window size*/
            switch(true) {
                case(w<200):
                    window.y='a1';window.e=0.8; /*tiny*/ 
                    break;
                case(w>=200&&w<=360):
                    window.y='a2';window.e=0.9;/*x small*/
                    break;
                case(w>360&&w<=480):
                    window.y='a3';window.e=1; /*small*/
                    break;
                case(w>480&&w<=768):
                    window.y='a4';window.e=1.1; /*medium*/
                    break;
                case(w>768&&w<=1280):
                    window.y='a5';window.e=1.3; /*large*/
                    break;
                case(w>1280&&w<=1920):
                    window.y='a6';window.e=1.6; /*x large*/
                    break;
                case(w>1920):
                    window.y='a7';window.e=1.9; /*xx large*/
                    break;
                default:
                    window.y='a5';window.e=1.2; /*default size */
                    break;
            }
            url=window.location.origin.concat('/',z[a.toString()],window.y,'.txt');

        } else {
            url=window.location.origin.concat('/',z[a.toString()]);
        }
        x[a].open("GET",url,true);

        x[a].onreadystatechange=function (z){
            if(x[a].readyState===4){
                if(x[a].status===200 || x[a].status==0){
                    window[a]=x[a].responseText;
                }
            }
        }
        x[a].send();
     });
}


A: Use Promises instead, and then you can use Promise.all, which will resolve when all promises in the passed array are resolved. Instead of forEaching over the keys of the passed object, .map each of the keys to a Promise instead:
const getProm = (url) => new Promise((resolve, reject) => {
  const x = new XMLHttpRequest();
  x.open("GET", url, true);
  x.onreadystatechange = function() {
    if (x.readyState === 4) {
      if (x.status === 200 || x.status == 0) {
        resolve(x.responseText);
      } else {
        reject(x.status);
      }
    }
  }
});

// J.o function 
o: function(z) {
  var g, h, x = [];
  const proms = Object.keys(z).map(function(a, b, c) {
    window[a] = null;
    x[b] = new XMLHttpRequest();
    const url = window.location.origin.concat('/', z[a.toString()]);
    return getProm(url)
      .then((responseText) => {
        window[a] = responseText;
      });
  });
  return Promise.all(proms);
}

// J.e function for styles
e: function(z) {
  var w, y, e, ar, x = [];
  const proms = Object.keys(z).map(function(a, b, c) {
    window[a] = null;
    if (a == 'm') {
      w = window.innerWidth; /*window size*/
      switch (true) {
        case (w < 200):
          window.y = 'a1';
          window.e = 0.8; /*tiny*/
          break;
        case (w >= 200 && w <= 360):
          window.y = 'a2';
          window.e = 0.9; /*x small*/
          break;
        case (w > 360 && w <= 480):
          window.y = 'a3';
          window.e = 1; /*small*/
          break;
        case (w > 480 && w <= 768):
          window.y = 'a4';
          window.e = 1.1; /*medium*/
          break;
        case (w > 768 && w <= 1280):
          window.y = 'a5';
          window.e = 1.3; /*large*/
          break;
        case (w > 1280 && w <= 1920):
          window.y = 'a6';
          window.e = 1.6; /*x large*/
          break;
        case (w > 1920):
          window.y = 'a7';
          window.e = 1.9; /*xx large*/
          break;
        default:
          window.y = 'a5';
          window.e = 1.2; /*default size */
          break;
      }
      url = window.location.origin.concat('/', z[a.toString()], window.y, '.txt');

    } else {
      url = window.location.origin.concat('/', z[a.toString()]);
    }
    return getProm(url)
      .then((responseText) => {
        window[a] = responseText;
      });
  });
  return Promise.all(proms);
}

Then, you can call Promise.all on the calls of J.o and J.e:
Promise.all([
  J.o({p:'/dir/file-1.txt'}),
  J.e({
    g:'/dir/file-2.txt',
    m:'/dir/prefix-',
    c:'/dir/prefix-string.txt'
  })
]).then(() => {
  console.log('All requests have finished');
})
.catch((e) => {
  // handle errors
});

Note that it'll be more elegant if you can manage to switch over to fetch instead of XMLHttpRequest - fetch returns a Promise already, so there's no need to explicitly construct a Promise with it:
const getProm = url => fetch(url).then((res => res.text());

But it's not supported in ancient browsers, so to use it reliably, you'll need a polyfill as well.
If the only reason you're assigning to window[a] is to be able to access the asynchronously returned values later, don't - instead, use the values the Promises resolve to. For example:
Promise.all([
  getProm('foo'),
  getProm('bar')
])
.then(([foo, bar]) => {
  // foo and bar are variables which hold the response text for foo and bar
});

As a side note, you might strongly consider debugging and altering only the source code, and not the minified code. Minified code is a pain to read.
