IE10 and jQuery: SCRIPT5009: "$" is undefined

BairDev picture BairDev · Jun 2, 2013 · Viewed 39.7k times · Source

I'm faced with this really annoying problem, it appears in IE10 like in IE9. Given this HTML:

<head>
    <title>Any Consult</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <!--[if lte IE 9]>
        <script src="scripts/IE9.js"></script>
    <![endif]-->
    <script type="text/javascript" src="scripts/jquery.js"></script>
    <script type="text/javascript" src="scripts/scripts.js"></script>
</head>

This (scripts.js) works fine in FF and Chrome, but IE10 throws the SCRIPT5009 error.

scripts.js is like (simple, but tested example):

$(document).ready(function() {
   alert('Hello');
});

IE10 does not load the jQuery-File and I tried nearly everything. I changed and reduced the filename, I spared the

<!--[if lte IE 9]>...

part, I tried

src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js"

but nothing happened. Because this is a new version of this question, I'd like to specify:

  1. how should I name the jQuery-File for IE(10)?
  2. where should I put the script tags in the HTML-Header?

Thanks a lot!

EDIT: Here the suggested HTML-version, which does not work, too:

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/scripts.js"></script>
<script type="text/javascript" src="scripts/clocks.js"></script>
<!--[if lte IE 9]>
    <script src="scripts/IE9.js"></script>
<![endif]-->
<!--[if IE]><script type="text/javascript" src="scripts/excanvas.js"></script><![endif]-->

IE9.js is a browser polyfill file.

And here is my screenshot ("ist undefiniert" means "is undefined", "Die Webseite reagiert nicht" means "the page went down", "Debugger beenden" means "stop debugging", $('.aLang') is a class in my HTML.

Screenshot IE10 Bug Report

Answer

Mike Kokitch picture Mike Kokitch · Jul 19, 2013

I had this problem with IE and found that the jQuery javascript file was corrupt in the IE developer tool. This was caused in my case by HTTP GZIP compression being done by the server but IE wasn't decompressing the file. I guess that if you turn off static HTTP compression or exclude the application/x-javascript from whatever is doing the compression (Mine was done by FluorineFX for all files over 10Kb) it should work okay once you have cleared your browser cache to get rid of the compressed javascript file.