0

It seems that IE8 defers javascript, but also doesn't block. I've setup a test environment to prove this. Here's the html page(replace 192.168.1.xxx with your server):

<html>
<head>
 <title>IE Pains</title>
 <script type='text/javascript' src='http://192.168.1.xxx/ietest/js.js'></script>
 <script type='text/javascript'>
  scream('hello world');
 </script>
</head>
<body>
</body>
</html>

And the js File:

function scream( str ) {
 alert( str );
}

Am I seeing this wrong, or does IE not recognize the scream function because it hasn't finished loading js.js?

EDIT: I created the pages on my server: http://www.codenothing.com/ietest/, which loads fine in IE8, but bringing it down to local machine, and going through local network seems to be failing. I have confirmed this on 2 different wireless networks going through the 192.168 protocol.

6
  • 1
    Are you sure the path to that js.js is correct? Commented Jun 8, 2010 at 19:05
  • It shouldn't be the case. Can you post the contents of your external js? Commented Jun 8, 2010 at 19:05
  • 1
    @Chetan - He did, in the question :) Commented Jun 8, 2010 at 19:06
  • @Nick: Aw crap. I blame it on my short attention span. Commented Jun 8, 2010 at 19:08
  • Is the calling page being executed via a file:// URI? or is it also an http page? That can make a difference. Commented Jun 8, 2010 at 19:12

1 Answer 1

2

Scripts are blocking in all browsers, including IE8, unless the async or defer attributes are present. Vast amounts of scripts rely on the predictability of script elements blocking parsing, including libraries and frameworks (for instance, how could you declare $(document).ready() if the browser didn't wait for the jQuery script to complete?)

Check the following:

  • There are no syntax errors or typos in the JS file.
  • The path to the JS file is correct.
  • The function is declared in the global scope.

You could even try the jQuery library itself:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(function(){
    alert("test");
});
</script>   
Sign up to request clarification or add additional context in comments.

1 Comment

Also, everything you said is right, that's why I am so confused as to why it's across only the local network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.