Answer the question
In order to leave comments, you need to log in
How to load JS file after some time interval?
Greetings!
Faced such a problem.
One-page online service in AngularJS.
In the first 10-15 seconds after loading, there is a very active interaction with the server -
JS is working, loading the data necessary for display.
Put Livesite. It starts downloading at the same time as my requests.
It is extremely important that JS gets everything it needs from the server as quickly as possible. And Zhivosayt gets confused under his feet with his download.
It is necessary that Live Site starts loading in 15-20 seconds after all components are loaded.
Is that possible?
I'm not asking as an expert. In order for the programmer to poke into a link or your answer and say "do it."
Answer the question
In order to leave comments, you need to log in
function loadScript(src) {
var s = document.createElement('script')
s.src = src
document.body.appendChild(s)
}
// и дальше в нужном месте вызываем
loadScript('path/to/my/script.js');
// или по таймауту
setTimeout(function() { loadScript('path/to/my/script.js') }, 15000);
Through $timeoutYou can do initializationIt is possible to load jivosite by callback when all requests are processed.
$scope.$watch(function() {
return $http.pendingRequests.length;
}, function(newVal) {
if (newVal === 0) {
(function loadScript(src) {
var scriptElement = document.createElement('script');
scriptElement.src = src;
window.document.head.appendChild(scriptElement);
})("/path/to/script/");
}
});
I won’t give a link, but you can dig towards using a combination of setTimeout () and JQuery .getScript () method
Here is what LiveSite support replied:
1) You need to wrap our script in setTimeout
2) admin.jivosite.com - settings - options - reload (enable),
3) There will be an update in October that will not block loading window
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question