How to make a download of the script after the onload event?

All kind time of day.

Develop the website. Since the site is quite weighty, it loads it is quite slow. But in order that the user saw the process of loading the website I made a preloader. The preloader I put on the event document.body.onload(). But in the download there are processes that could send the user to, such as getting a list of videos with Vimeo.com, get photos from a vk.com. That is, at the time when these resources are loaded, the loading animation appears "loading" and, in principle, for a user do not have to wait for a full load of these resources, as they are loaded asynchronously via Ajax. But how to make the preloader stopped working after the page has loaded, but before loading the Ajax data? In principle, the logic may be this: in the onload function to disable the preloader and start the Ajax load the data, But the point is that Ajax logic is in another file and connects to a separate script file.
June 14th 19 at 21:06
2 answers
June 14th 19 at 21:08
Solution
You can also insert a separate script in a simple way
var scrpt = document.createElement('script');
scrpt.src = '.../...';
document.body.appendChild(scrpt);

The preloader will end and inserted the script will be executed.
exactly! It's good, Yes, thank you! - dayna_McKenzie31 commented on June 14th 19 at 21:11
June 14th 19 at 21:10
Google dom ready or DOMContentLoaded.
Well, or at the end of the page put this js
Yes, DOMContentLoaded stop the preloader, then the user will be able to use the page. - dayna_McKenzie31 commented on June 14th 19 at 21:13
well, thank you! - rhianna_Fee commented on June 14th 19 at 21:16
and thank you! - dayna_McKenzie31 commented on June 14th 19 at 21:19

Find more questions by tags CSSJavaScriptHTML