13

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.

4
  • Is it not loading at all or are you calling the javascript function before the page has fully loaded? In other words, what are you using to trigger calling myfunction? Commented Mar 24, 2009 at 16:38
  • @Keltex-The missing function is being called later in the app. And the code I said I was stepping through is variable declarations and other simple code like that. Commented Mar 24, 2009 at 16:40
  • A couple more questions: Have you tried turning off script debugging? Are you using IIS or the built-in web server? Commented Mar 24, 2009 at 17:18
  • No, I did not turn off script debugging in IE, and I'm using the built in Visual Studio web-server. I will try that, but right now I'm having an issue where the problem is not ocurring. Commented Mar 24, 2009 at 18:06

9 Answers 9

6

I've had this problem twice before. It's always a syntax error in the Javascript code. Most probably an extra bracket or a missing one. All other browsers let it through but IE7 wasn't.

Trial and error (removing chunks and chunks of code) led me to finding the solution.

I hope this helps :-)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the insight, but I don't think this was the problem. As I stated in the question, sometimes it gets downloaded, sometimes it doesn't. When it does load, the script is fine. But thanks again.
I just had the same problem. Browser would not recognise the code but would also not throw any errors. The script tag was correct, the code was loading when I viewed source and followed the link to the include file. Turns out I had a syntax problem.
Watch your commas is all I'm saying just spent ages trying to debug. IE would only report errors if I declared my script like so: <script language="javascript" type="text/javascript" src="/js/orderform.js"></script>
5

Just in case the answers given have not worked -

IE7 by default does not load Javascript from local files. Usually, you'll get the information bar dropping down and indicating that. You have to click on the bar and select "Allow blocked content" and then IE7 will reload the page with Javascript enabled.

This behaviour is consistent. However, if some systems disable the display of the Information Bar, there is now way you can get to know what the problem is.

My suggestion is to add a < noscript > tag on top of your HTML page and stylize it with a bold red background using CSS so that you cannot miss it. StackOverflow uses this technique.

This way you'll surely get to know if Javascript is not loading due to Security reasons.

2 Comments

@globetrotter-Thanks, that sounds like a good technique. However, I've got a bunch of scripts, and all the others load just fine. Even this one loads ok, 60% of the time. But for some reason I cannot phathom, it occasionally doesn't load. ??? :-(
I had this issue (script not loaded under MSIE7, but loaded under MSIE9 and Firefox). This was caused by MSIE7 security settings. The <noscript> tag helped to detect the issue.
4

Just an FYI for anybody having the same problem.

This was never resolved, but I now believe it had something to do with Visual Studio Development Server, and I question if this would have happened had I been using IIS. Unfortunately, I no longer work on that project, so I cannot test it.

Comments

4

I had the same exact problem as the original poster and had tried many of the solutions provided to no avail.

I finally fixed it by updating the date and time on the machine running the apache server. It was off by a couple days (result of running intermittently in a VM)

Hope this helps someone.

Comments

2

Instead of src="js/AjaxTry.Utility.js" try this:

src="<% ResolveUrl("~/path/from/root/to/js/Ajax.Utility.js") %>

1 Comment

Thanks, I know where your coming from, but it's not an issue of not finding the js file, since sometimes it's there ... actually it's ussually there.
1

Another thought: are you flushing the browser cache between tests? A browser is perfectly at liberty to cache scripts as it sees fit unless prevented from doing so - normally you only noticed if editing scripts and stylesheets and images

1 Comment

Before I put the file version parameter in the query string, I was doing it religiously, but since then I've slacked off. I will start doing that again, but I'm pretty sure this was happening when I was clearing the cache regularly.
1

Have you checked with a tool like Fiddler that the call for that .js file is being made to either the server or the browser cache, and that the browser is actually recieving the file correctly, and not getting a 404 or some such?

You should check this on the page that's actually calling the method in question - as your path is a relative url (i.e. doesn't start with a "/"), is there any possiblity that the page you are calling it from isn't below the js folder but perhaps beside it?

Imagine a site structure like this from the root of the site:

/page1.aspx
/folder/page2.aspx
/js/Ajax.Utility.js

If both page1 and page2 have your call to the .js file, only page1 will actually be able to use retrieve it correctly - page2 will effectively be looking for:

/folder/js/Ajax.Utility.js

1 Comment

@Zhaph - Ben Duguid-since the problem is only occurring ocasionally, it can't be a path problem. But the fiddler idea is a good idea to issolate if the problem is the webserver of IE. +1
1

I had the same problem with IE7, the problem was in that I used 'super' as a property which is a reserved keyword and IE7 silently did not load the page.

Comments

1

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.

Comments

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.