Best way to reverse the slow loading of JS remote call
I have a remote JS that should appear at the beginning of the document. If the server is slow or unavailable, it is obviously slowing down or preventing the page from loading. I was looking for an easy way to set a limit of 3 seconds (maybe less) so that it would give up and just not load the functionality.
Does anyone have an easy way to do this with Javascript only?
+1
source to share
3 answers
Include the .JS file after the download is complete.
<script type='text/javascript'>
window.onload = function(){
document.write("<script type='text/javascript' src='http://domain.com/file.js'></script>");
}
</script>
Put this in the HEAD of your document, then the file will start loading when the page finishes loading.
+2
source to share