I don’t know how the questioner defines it before the website is opened?
If you just want the web page to load js files earlier, you can put the script reference in the head tag. However, the question also requires that the web page code does not display the js after opening. This is how I understand it. In this case, there are two main steps:
Write an inline js code in the head tag. The main function of the code is to introduce the js file and follow-up actions
The so-called follow-up action is to trigger the loading event after introducing the file to remove the introduction of the file from the document dom
Use a web server (such as nginx) to insert content into the page? Then this js is also monitoring whether the page has been loaded, and deletes itself after loading.
I don’t know how the questioner defines it before the website is opened?
If you just want the web page to load js files earlier, you can put the script reference in the head tag.
However, the question also requires that the web page code does not display the js after opening. This is how I understand it. In this case, there are two main steps:
Write an inline js code in the head tag. The main function of the code is to introduce the js file and follow-up actions
The so-called follow-up action is to trigger the loading event after introducing the file to remove the introduction of the file from the document dom
I will simply list a demo:
First prepare the page t.html
Introduced js: t.js
I wonder if this is the main effect of the question?
If you want to improve the loading speed, you can use cache to load js in advance. I have never encountered this before
Use a web server (such as nginx) to insert content into the page?
Then this js is also monitoring whether the page has been loaded, and deletes itself after loading.
Try putting the actual web page in the iframe and js outside the iframe?