简体   繁体   中英

Why does Javascript sometimes not load in IE8

I have external javascript files that get loaded in my master page.

Sometimes in IE8, my javascript files don't load correctly and the browser throws a bunch of javascript errors saying 'object not recognized.'

If I refresh the page then everything is fine. If I click on a link then the problem sometimes occurs again.

I have meta tags in my header for clearing out the cache on each request. I'm using the head.load library to load my js files in parallel.

The head.load library is located in my header and the external files are at the end of my body.

Please remember that this problem only occurs in IE8. So my question is..drum roll please..is there a hack that I can use to make sure my javascript files are loaded correctly each time the page loads for IE8?

Any help would be greatly appreciated.

Updated as requested

<head runat="server">
    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
    <meta http-equiv="PRAGMA" content="NO-CACHE" />
    <meta http-equiv="EXPIRES" content="-1" />
    <script type="text/javascript" src="scripts/js/head.load.min.js"></script>
</head>
<body>
<script type="text/javascript">
    head.js("scripts/js/jquery-1.6.2.min.js");
    head.js("scripts/js/jquery.cookie.js");
    head.js("lib/gritter/jquery.gritter.min.js");
    head.js("lib/fancybox/jquery.easing-1.3.pack.js");
    head.js("lib/fancybox/jquery.fancybox-1.3.4.pack.js");
    head.js("scripts/js/jquery.microaccordion.js");
    head.js("scripts/js/jquery.stickyPanel.js");
    head.js("scripts/js/guidely.js");
    head.js("scripts/js/pto.js");
</script>
</body>

Ok, the problems appears to be how the head.load library loads my externals in IE8. If I load jquery before I load the head.load library, and then load my externals in parallel at the end of the page; then there's no javascript errors. A little lesson for myself about javascript loading and IE8.

Thank-you everyone for the input.

@ frederic - I work at a company that has 188,000 employees. If a user has an add on installed in their browser that is causing my page to crash then there's nothing I can do about that. I also don't think this problem is being caused by any add ons. Its just how the head.load library is handled in IE8.

<head runat="server">
    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
    <meta http-equiv="PRAGMA" content="NO-CACHE" />
    <meta http-equiv="EXPIRES" content="-1" />
    <script type="text/javascript" src="scripts/js/jquery.min.js"></script>
    <script type="text/javascript" src="scripts/js/head.load.min.js"></script>
</head>

<script type="text/javascript">
    head.js("scripts/js/jquery.cookie.js");
    head.js("lib/gritter/jquery.gritter.min.js");
    head.js("lib/fancybox/jquery.easing-1.3.pack.js");
    head.js("lib/fancybox/jquery.fancybox-1.3.4.pack.js");
    head.js("scripts/js/jquery.microaccordion.js");
    head.js("scripts/js/jquery.stickyPanel.js");
    head.js("scripts/js/guidely.js");
    head.js("scripts/js/pto.js");
</script>

Look at the page http://headjs.com/ in the section Usage you will see exactly what is wrong with your code:

// files are loaded in parallel and executed in order they arrive head.js("file1.js"); head.js("file2.js"); head.js("file3.js");

Your scripts are been loading in parallel and are executed in arrival time, that's pretty bad for the deps on jquery, if you want them to be executed in order use this:

head.js("scripts/js/jquery-1.6.2.min.js",
        "scripts/js/jquery.cookie.js",
        "lib/gritter/jquery.gritter.min.js"),
        "lib/fancybox/jquery.easing-1.3.pack.js",
        "lib/fancybox/jquery.fancybox-1.3.4.pack.js",
        "scripts/js/jquery.microaccordion.js",
        "scripts/js/jquery.stickyPanel.js",
        "scripts/js/guidely.js",
        "scripts/js/pto.js");

You need to call js with a list of resources to load, not just call js several times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM