Best practice to load settings to the web application I have to load settings to an app when it's opened (It's an Electron application and I'm loading settings from the local json file)



I'm loading settings right after the page is loaded:

document.onreadystatechange = function(){
    if (document.readyState === 'complete'){
        loadSettings();
    }
}


but I think this is not the right way to do it because at first, the page sets inputs, like checkboxes, as they are in HTML file and only after that, changes their values again according to settings.
I want to know what is the best practice to load the settings to a web app.
I can't claim to be familiar with Electron, but after looking at the documentation and an example on github, it appears that an electron convention is to use app.on/app.once


var electron = require('electron') // http://electron.atom.io/docs/api
var path = require('path')         // https://nodejs.org/api/path.html
var url = require('url')           // https://nodejs.org/api/url.html
var window = null
// Wait until the app is ready
electron.app.once('ready', function () {
  // Create a new window
});



In general, Javascript developers can subscribe to the readystatechange event as you have done, as well as use document.addEventListener() to subscribe to the DOMContentLoaded event:



document.onreadystatechange = function(){
  console.log('document readystate: ',document.readyState);
}
document.addEventListener('DOMContentLoaded',function() {
  console.log('DOM Load: document readystate: ',document.readyState);
})




You might find this SO post interesting...