I have a single page web app. Some of its behaviour relies on modifying a section of the page and then call some functions to format this section AFTER it has been modified (MathJax being one of the most important post modification calls I need to do).
Since Ajax is asynchronous, some of the time I didn't get the desired effect as I would get a non-formatted page, since the scripts would run before the contents of the page were ready, to fix this I started to call XMLHttpRequest().open()
with false
to make it synchronous and ensure that the page contents were ready before calling the scripts.
This however makes the page throw a warning
"Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience."
despite behaviour being exactly what I need. I don't like relying on deprecated behaviour because it may work now, but 2 months down the road if they change things and break it, I'd have to reformat my entire code and solve the problem again in a different way.
How concerned should I be about this warning, and if it's likely to be broken in future updates of the web, what should I do instead?
EDIT: JS code:
function changeSection(section, page, button, sync=true)
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
$(section).empty();
$(section).append(this.responseText);
clearButtons();
setButton(button);
}
};
xhttp.open("GET", page, sync);
xhttp.send();
}
function setLagrange() {
path = MathLog_path + "modelling/lagrange_interpolation.html";
changeSection("#VolatileSection", path, "lagrange_button", false);
$('pre code').each(function(i, block) {
hljs.highlightBlock(block);
});
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}