Why are all the script inserted by jsonp in head?

Why are all the script inserted by jsonp in head? Instead of the bottom of the body?

Aug.30,2021

this is related to the library you use, because the script tag is also dynamically inserted into the page after the request is completed, and the location is related to the library.


can also be found in body, refer to the example of w3schools :

function clickButton() {
    var s = document.createElement("script");
    s.src = "demo_jsonp.php";
    document.body.appendChild(s);
}


because the library is set like this

it's good to think about it, and if you insert body, it's likely that body hasn't been loaded yet.

of course, it is also possible that head did not finish loading, but at least it is much safer than body, because it must be finished loading head, first and then loading body

.
Menu