As the title says, I am facing a crossroads regarding how to use the information collection methods (a json file in a route), whether to do it synchronously or asynchronously.
The problem I run into when doing it asynchronously is that I can't store anything globally until the function stack is done. So many times I pick variables to null.
Regarding the synchronous way, the browser already tells me that you are working with obsolete things, which will affect the user.
In conclusion. I don't know which way to go. If there was some way to collect that information asynchronously, and in a loop (setInterval), and then store it in a global variable only if there was any change, that would be great.
Right now I have this code to collect the data:
//URL para obtener los datos.
var requestURL = "data.geojson";
//Objeto de petición.
var request = new XMLHttpRequest();
//Métodos para realizar una petición de datos a una URL, mediante el método GET y con una cabecera personalizada.
request.open('GET', requestURL, false);
request.send();
if ((request.readyState == 4) && (request.status === 200)) {
data = request.responseText;
}