Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my javascript files not loading 'consistently' in IE7?

In what seems to be random occurrences, javascript files are not loading.

I believe this diagnosis is correct because a) I have code to check, b) I've stepped through the code, and c) I get “'myfunction' is undefined” error when functions in those files are used.

Sometimes this doesn’t happen for an hour, sometimes it happens every time I load the page, sometimes it happens every other time I load the page. It seems like every time I identify a consistent behavior so I can repeat it and diagnose it, it changes!

Does anybody have any idea what might be causing this?

I'm using :

  • IE version 7.0.5730.11 (had & uninstalled IE8 Beta)
  • VS2008

Right now, it appears to only be happening to my colleague and I on our development environments.

There is one script which appears to be missing more than any other. Here's the script tag.

<script language="javascript" 
        type="text/javascript" 
        src="js/Ajax.Utility.js?<%= ConfigurationManager.AppSettings["WebApp.JavaScript.FileVersion"].ToString() %>"></script>

Which evaluates to

<script language="javascript" 
        type="text/javascript" 
        src="js/Ajax.Utility.js?090324a"></script>

The version query string parameter doesn't appear to have any effect either since I've both had and not had the problem immediately after changing it.

like image 529
John MacIntyre Avatar asked Mar 24 '09 16:03

John MacIntyre


People also ask

How do I force a JavaScript file to load?

js and . css files. That is the reason those new changes will not appear to the user. The user either has to clear the browser cookie & reload the page or else he or she has to do a hard refresh of the page by pressing Ctrl+F5.

Why js file is not working in HTML?

Most likely, the problem is that you are including your js file in a head tag or somewhere above your main content. By doing this, you are executing your js code before full html content has been attached. As a result, when your js code executes, it does not recognize any html element because there isn't any.

What is the most appropriate file to configure external .js files?

An external JavaScript file must be saved by . js extension. It is recommended to embed all JavaScript files into a single file. It increases the speed of the webpage.


1 Answers

Most browsers seem tolerant to additional commas, e.g. in a definition of a list of object properties:

var obj = {prop1: 'value',
           prop2: 'value',};

Internet Explorer is not tolerant to the final comma. Whenever I've had this problem it's ALWAYS proved to be due to an additional comma. Moreover the IE debugger doesn't flag the source problem, it just decries the missing definition(s) from the file that hasn't loaded properly.

like image 98
James Firth Avatar answered Oct 18 '22 04:10

James Firth