I was testing and see if I can use javascript to load .js after the document is ready, and got this warning message from chrome:
"Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience."
My codes are like:
$(document).ready(function(){
var s=$('<script src="test.js"></script>');
$('body').append(s);
});
My questions are:
1) In this case, what is considered a "Synchronous XMLHttpRequest"? I think it is related to the loading of 'test.js', but if I change it to var s=$('<img src="image.png"></img>');
the warning message won't show.
2) If the .js file has to be loaded this way, what is the best practice?
*********** Editting ***********
The content of test.js is
console.log(document.getElementsByTagName('h1'))
There is a h1
in HTML.