Take the 2-minute tour ×

I have a remote JS that must appear in the head of the document. If the server is slow to respond or inaccessible, obviously this slows or prevents the page from loading. I have been searching for a simple way to set a limit of say 3 seconds (probably less) for it to give up and simply not load the functionality.

Does anyone have a simple way to do this with Javascript only?

share|improve this question

3 Answers 3

Include the .JS file after the page is done loading:

<script type='text/javascript'>
window.onload = function(){
 document.write("<script type='text/javascript' src='http://domain.com/file.js'></script>");

Place that in the HEAD of your document, then the file will start loading when the page has finished loading.

share|improve this answer

If that is an issue, split the .js apart and have the low end css functions in the and the slow ones in the onload="";

share|improve this answer

If window.onload event is invoked too late for you, then just inline your javascript file directly into the page.

share|improve this answer

Your Answer


