Opened 6 years ago

Closed 3 years ago

#16927 closed defect (patchwelcome)

IE + Dojo + CDN + Modernizr.load()

Reported by: bishop Owned by: Rawld Gill
Priority: low Milestone: 1.13
Component: Loader Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

Summary: Modernizr loads dojo over CDN, then loads a local script that does all the work (require, business logic, etc.). If that script requires a package that is in the CDN file system, but not in the CDN dojo.js, IE throws an error at dojo/dojo.js:1662.

In this scenario, this exception is 100% repeatable in IE only (IE8/Win7 and IE9/Win7 specifically). No other browser I tested has any issue.

If Modernizr is eliminated from the equation, if a local Dojo install is loaded by Modernizr, if a CDN Dojo is loaded with a <script> tag, or if the the local script is moved inline, the behavior disappears and IE behaves like every other browser I've tested.

Using the latest Modernizr (2.6.2) and Dojo (1.8.3).

Reproduction:

<!DOCTYPE html>
<html>
    <head>
        <script type='text/javascript' src='/modernizr/2.6.2/modernizr.min.js'></script>
    </head>
    <body>
        <script type='text/javascript'>
            Modernizr.load([
                { load:'//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js' },
                { load:'/source.js' }
            ]);
        </script>
    </body>
</html>

and (this is source.js referenced above):

require(
    [
        'dojo/aspect',                  // will load
        'dojo/data/ItemFileReadStore',  // will throw an exception on IE8+
        'dijit/layout/BorderContainer', // "
        'dojox/color'                   // "
    ],
    function (aspect, ItemFileReadStore, BorderContainer, color) {
        console.log('all done');
    }
);

It does not matter whether Modernizr load is invoked from <head> or <body>.

This may very well be a bug in my understanding. I have tried async:false, parseOnLoad:false, and dojoBlankHtmlUrl:'/path/to/local/blank.html' configuration values to no avail. I also double checked that I wasn't encountering any of the IE "no more than 30 scripts" issue. I did not try different CDN, but I manually poked around the Google CDN tree and saw that the files were in the expec

Change History (8)

comment:1 Changed 6 years ago by bishop

Finish truncated comment from "the files were in the expec...":

expected location.

Some DuckDucking? suggests other have a "similar" problem, eg: http://stackoverflow.com/questions/14635490/load-dojo-from-cdn-using-jquery

Anyway, assuming I've not missed something, this very well may still not be a Dojo issue. However since the require works for some browsers and some requires, it seemed appropriate to file this first with Dojo.

With respect to the code above, my expectation is that the "all done" message will console log in all browsers, whether Dojo is loaded via Modernizr either from CDN or locally.

comment:2 Changed 6 years ago by Rawld Gill

Owner: changed from Rawld Gill to bishop
Priority: undecidedlow
Status: newpending

Hi bishop,

Thanks for the report. I appreciate your efforts to track this down. Unfortunately, I don't have free time to debug your particular environment. If you could reduce this to a simple, reproducible test case, I will be happy to look into it further.

comment:3 Changed 6 years ago by bishop

Status: pendingnew

Is this any simpler?

index.html

<!DOCTYPE html>
<html>
    <head>
        <script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js'></script>
    </head>
    <body>
        <script type='text/javascript'>
            Modernizr.load([
                { load:'//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js' },
                { load:'source.js' }
            ]);
        </script>
    </body>
</html>

source.js

require(
    [
        'dojo/aspect',                  // will load
        'dojo/data/ItemFileReadStore',  // will throw an exception on IE8+
        'dijit/layout/BorderContainer', // "
        'dojox/color'                   // "
    ],
    function (aspect, ItemFileReadStore, BorderContainer, color) {
        console.log('all done');
    }
);

Nothing to download. In IE8/Win & IE9/Win (maybe older, didn't try), fails with readyState errors at the line I previously indicated. Works flawlessly -- console shows 'all done' -- in all other browsers I tried (FF, Chrome, etc.).

comment:4 Changed 6 years ago by bishop

From the stackoverflow link I posted, this comment seems most relevant:

"The "Node was not found" error is caused by the loader trying to locate the script tag that loaded it. This is a trick that Dojo uses when it is loaded from a CDN (like the Google one you have used) to try to find the url path for loading modules.

The jQuery $.getScript() function is not actually injecting a script tag into the page but rather loading via XHR and then evaling the code. Hence, the tag that Dojo is looking for cannot be found. This only happens when using a CDN. If you used your own local copy of Dojo rather than a CDN, it can be made to work."

In my case, I'm using Modernizr, not jQuery. But if this "trick" is indeed true, then any one trying to load Dojo over CDN from an XHR loader will suffer the same problem in IE.

Not saying this necessarily needs any code fix, but a documentation note might save some folks some pain.

comment:5 Changed 6 years ago by bill

Status: newpending

Isn't that exactly the same code you posted originally? I think what Rawld wanted was a testcase that didn't pull in all of Modernizer.

comment:6 Changed 6 years ago by bishop

Status: pendingnew

No, it's not the same. In the original posting, one had to build and download modernizer. In the new posting, modernizer is loaded off of CDN -- nothing to download.

The test case requires Modernizr (or JQuery, or any other XHR loader). The issue I am reporting is that -- on IE only -- Dojo fails to load some modules via require() when Dojo itself is loaded by an XHR loader (vs Dojo being loaded by <script>).

comment:7 Changed 6 years ago by bill

Owner: changed from bishop to Rawld Gill
Status: newassigned

Not sure what "any other XHR loader" means, if it's just a few lines of code it might be simpler to use those lines rather than including a whole other package. Anyway, passing ticket to Rawld for him to accept or reject.

comment:8 Changed 3 years ago by dylan

Milestone: tbd1.12
Resolution: patchwelcome
Status: assignedclosed

Given that no one has shown interest in creating a patch in the past 2+ years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.