Can you take a look at the purpose of this js? It's about the js of Baidu automatically submitting links.

first look at the code as follows

<script>
(function(){
    var bp = document.createElement("script");
    var curProtocol = window.location.protocol.split(":")[0];
    if (curProtocol === "https") {
        bp.src = "https://zz.bdstatic.com/linksubmit/push.js";
    }
    else {
        bp.src = "http://push.zhanzhang.baidu.com/push.js";
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>

does this code mean that the js file is externally referenced (2 choose 1) and placed in front of all script tags, that is, the js is required to be executed first, is that right?

Mar.31,2021

create a script tag, select a different address according to the current URL protocol, and then insert this script tag in front of the first script tag of the page. But the first execution is not necessarily. Depending on where the code is placed, other script tags in front of it may have been executed before the code is executed.


this code is not high-tech, it is the most normal dynamic script injection technique.
is also a way to load js scripts asynchronously, as many on-demand asynchronous loads do.

it's OK for you to put it in front of all script tags, but the execution order is not guaranteed, because it is loaded asynchronously, you need to download the js script file through the request network and trigger the load event to execute.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5972b-4553d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5972b-4553d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?