graceful handling of cross-domain dojo.require timeouts/404s

View: New views
6 Messages — Rating Filter:   Alert me  

graceful handling of cross-domain dojo.require timeouts/404s

by andrewtrafford@btinternet.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Googl(e)ing for "uncaught exception: Could not load cross-domain
resources" seems only to give results for avoiding the error (using the
build system properly, baseUrl, dojo.xd.js vs dojo.js and so on).

I'm fine with that, but what I'd like to do is to catch and gracefully
handle this exception when it occurs legitimately due to my server's
loading / outage, and offer the user a better response than a straight
javascript error.

Here's some code which demonstrates the problem:

    <script type="text/javascript">
        djConfig = {
            xdWaitSeconds: 5,
            useXDomain: true                
        };
    </script>
    <script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.3/dojo/dojo.xd.js"></script>
    <script type="text/javascript">
        dojo.require("not.exist");
        dojo.addOnLoad(function(){
            console.log('in-flight downloads completed');
        };
    </script>

Due to the cross-domain setup, dojo.require returns immediately and the
addOnLoad is registered. Five seconds later the uncaught exception is
thrown and the only way I have found to catch it is window.onerror, but
I really don't want to do this as it is way too broad in scope and the
error information is not very useful.

I caught a whiff of djConfig.ioPublish  and dojo._xdInflight - but these
seem to involve hooking up to underscored internals which I am wary of,
and may even have been deprecated?

I suppose I could setTimeout and use a try/catch block to see if a
method in the required module exists at intervals, but is there a better
way of catching and handling these exceptions via dojo?

Thanks for reading.

Andy T
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: graceful handling of cross-domain dojo.require timeouts/404s

by James Burke-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I assumed that if a script cannot be loaded, it should trigger an
error. Right now the best way to handle it is use window.onerror and
inspect the error to determine the cause.

James

On Sat, Nov 7, 2009 at 3:46 AM, andrewtrafford@...
<andrewtrafford@...> wrote:

> Hi,
>
> Googl(e)ing for "uncaught exception: Could not load cross-domain
> resources" seems only to give results for avoiding the error (using the
> build system properly, baseUrl, dojo.xd.js vs dojo.js and so on).
>
> I'm fine with that, but what I'd like to do is to catch and gracefully
> handle this exception when it occurs legitimately due to my server's
> loading / outage, and offer the user a better response than a straight
> javascript error.
>
> Here's some code which demonstrates the problem:
>
>    <script type="text/javascript">
>        djConfig = {
>            xdWaitSeconds: 5,
>            useXDomain: true
>        };
>    </script>
>    <script type="text/javascript"
> src="http://o.aolcdn.com/dojo/1.3/dojo/dojo.xd.js"></script>
>    <script type="text/javascript">
>        dojo.require("not.exist");
>        dojo.addOnLoad(function(){
>            console.log('in-flight downloads completed');
>        };
>    </script>
>
> Due to the cross-domain setup, dojo.require returns immediately and the
> addOnLoad is registered. Five seconds later the uncaught exception is
> thrown and the only way I have found to catch it is window.onerror, but
> I really don't want to do this as it is way too broad in scope and the
> error information is not very useful.
>
> I caught a whiff of djConfig.ioPublish  and dojo._xdInflight - but these
> seem to involve hooking up to underscored internals which I am wary of,
> and may even have been deprecated?
>
> I suppose I could setTimeout and use a try/catch block to see if a
> method in the required module exists at intervals, but is there a better
> way of catching and handling these exceptions via dojo?
>
> Thanks for reading.
>
> Andy T
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: graceful handling of cross-domain dojo.require timeouts/404s

by andrewtrafford@btinternet.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi James,

Thanks for the response - I guess I just needed expert confirmation that
using onerror was the way to go and would not clash with dojo.

I have found that the most difficult part of learning dojo is knowing
when to use DOM functionality vs when to use dojo - I know that the
answer is generally 'if dojo offers it there's a good browser compat
reason, so use the dojo approach' - the trick is quickly finding out if
dojo does offer it :-)

It would be great if there were an equivalent of 'Javascript: the good
parts' for the DOM in which I could scribble my 'dojo does it even
better' margin notes...

Thanks very much for the confirmation,

Andy T

James Burke wrote:

> I assumed that if a script cannot be loaded, it should trigger an
> error. Right now the best way to handle it is use window.onerror and
> inspect the error to determine the cause.
>
> James
>
> On Sat, Nov 7, 2009 at 3:46 AM, andrewtrafford@...
> <andrewtrafford@...> wrote:
>  
>> Hi,
>>
>> Googl(e)ing for "uncaught exception: Could not load cross-domain
>> resources" seems only to give results for avoiding the error (using the
>> build system properly, baseUrl, dojo.xd.js vs dojo.js and so on).
>>
>> I'm fine with that, but what I'd like to do is to catch and gracefully
>> handle this exception when it occurs legitimately due to my server's
>> loading / outage, and offer the user a better response than a straight
>> javascript error.
>>
>> Here's some code which demonstrates the problem:
>>
>>    <script type="text/javascript">
>>        djConfig = {
>>            xdWaitSeconds: 5,
>>            useXDomain: true
>>        };
>>    </script>
>>    <script type="text/javascript"
>> src="http://o.aolcdn.com/dojo/1.3/dojo/dojo.xd.js"></script>
>>    <script type="text/javascript">
>>        dojo.require("not.exist");
>>        dojo.addOnLoad(function(){
>>            console.log('in-flight downloads completed');
>>        };
>>    </script>
>>
>> Due to the cross-domain setup, dojo.require returns immediately and the
>> addOnLoad is registered. Five seconds later the uncaught exception is
>> thrown and the only way I have found to catch it is window.onerror, but
>> I really don't want to do this as it is way too broad in scope and the
>> error information is not very useful.
>>
>> I caught a whiff of djConfig.ioPublish  and dojo._xdInflight - but these
>> seem to involve hooking up to underscored internals which I am wary of,
>> and may even have been deprecated?
>>
>> I suppose I could setTimeout and use a try/catch block to see if a
>> method in the required module exists at intervals, but is there a better
>> way of catching and handling these exceptions via dojo?
>>
>> Thanks for reading.
>>
>> Andy T
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>>    
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>  

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: graceful handling of cross-domain dojo.require timeouts/404s

by seth lytle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i'll second james comment about knowing when it's ok to use the DOM
... i'll usually check dojocampus, check quirksmode, maybe mumble
something on irc, check the dojo source for a place where it's doing
something similar. but figuring out what the "right" way of doing
something is a challenge. i'm in the process of trying to figure out
whether to use DOM methods or innerHTML for my content creation ...


On Sun, Nov 8, 2009 at 5:15 AM, andrewtrafford@...
<andrewtrafford@...> wrote:

> Hi James,
>
> Thanks for the response - I guess I just needed expert confirmation that
> using onerror was the way to go and would not clash with dojo.
>
> I have found that the most difficult part of learning dojo is knowing
> when to use DOM functionality vs when to use dojo - I know that the
> answer is generally 'if dojo offers it there's a good browser compat
> reason, so use the dojo approach' - the trick is quickly finding out if
> dojo does offer it :-)
>
> It would be great if there were an equivalent of 'Javascript: the good
> parts' for the DOM in which I could scribble my 'dojo does it even
> better' margin notes...
>
> Thanks very much for the confirmation,
>
> Andy T
>
> James Burke wrote:
>> I assumed that if a script cannot be loaded, it should trigger an
>> error. Right now the best way to handle it is use window.onerror and
>> inspect the error to determine the cause.
>>
>> James
>>
>> On Sat, Nov 7, 2009 at 3:46 AM, andrewtrafford@...
>> <andrewtrafford@...> wrote:
>>
>>> Hi,
>>>
>>> Googl(e)ing for "uncaught exception: Could not load cross-domain
>>> resources" seems only to give results for avoiding the error (using the
>>> build system properly, baseUrl, dojo.xd.js vs dojo.js and so on).
>>>
>>> I'm fine with that, but what I'd like to do is to catch and gracefully
>>> handle this exception when it occurs legitimately due to my server's
>>> loading / outage, and offer the user a better response than a straight
>>> javascript error.
>>>
>>> Here's some code which demonstrates the problem:
>>>
>>>    <script type="text/javascript">
>>>        djConfig = {
>>>            xdWaitSeconds: 5,
>>>            useXDomain: true
>>>        };
>>>    </script>
>>>    <script type="text/javascript"
>>> src="http://o.aolcdn.com/dojo/1.3/dojo/dojo.xd.js"></script>
>>>    <script type="text/javascript">
>>>        dojo.require("not.exist");
>>>        dojo.addOnLoad(function(){
>>>            console.log('in-flight downloads completed');
>>>        };
>>>    </script>
>>>
>>> Due to the cross-domain setup, dojo.require returns immediately and the
>>> addOnLoad is registered. Five seconds later the uncaught exception is
>>> thrown and the only way I have found to catch it is window.onerror, but
>>> I really don't want to do this as it is way too broad in scope and the
>>> error information is not very useful.
>>>
>>> I caught a whiff of djConfig.ioPublish  and dojo._xdInflight - but these
>>> seem to involve hooking up to underscored internals which I am wary of,
>>> and may even have been deprecated?
>>>
>>> I suppose I could setTimeout and use a try/catch block to see if a
>>> method in the required module exists at intervals, but is there a better
>>> way of catching and handling these exceptions via dojo?
>>>
>>> Thanks for reading.
>>>
>>> Andy T
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://docs.dojocampus.org
>>> Dojo-interest@...
>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>
>>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>>
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: graceful handling of cross-domain dojo.require timeouts/404s

by martingaleh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

seth lytle <srlytle.list <at> gmail.com> writes:

>
> i'll second james comment about knowing when it's ok to use the DOM
> ... i'll usually check dojocampus, check quirksmode, maybe mumble
> something on irc, check the dojo source for a place where it's doing
> something similar. but figuring out what the "right" way of doing
> something is a challenge. i'm in the process of trying to figure out
> whether to use DOM methods or innerHTML for my content creation ...

Wow, I have that same problem, even with whether to use javascript or dojo.  I
thought it was because I was working my way
through the russell book and after I'm done, I'd be all knowing and capable
and stuff.  It's good to know I'm not the only one, this dojo thing is really
difficult to learn.
what's irc?  I've heard of it, but I"ve never used it.


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: graceful handling of cross-domain dojo.require timeouts/404s

by andrewtrafford@btinternet.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I too started off thinking that dojo was difficult to learn, but I'm
begining to think that actually it is learning the DOM, CSS and DOM /
javascript interaction in a cross browser environment which is difficult.

Dojo is attempting to provide a unified approach where no such approach
exists at present (or in the recent browser past), so it is of necessity
complex, but probably less complex than doing it without dojo.

As soon as payday comes around again, I'm going to try the following:

Buy copy of Dynamic HTML: The Definitive Reference, Danny Goodman ISBN:
0596527403

This book shows all objects, methods and events to be found in (most)
browsers and tells you which browser make and version supports it/them.
 From here you can see incompatibilities much more clearly. It was
published end of 2007, so should be about the right era for dojo's
inspiration.

Then:
If I want to do something and I'm not *sure* dojo has an API for it,
check the book
If it looks like a mire of cross-browser differences, be reasonably sure
that dojo will offer a better way (or if it doesn't, ask if there is
another way)
If it looks uniform across browsers, do that bit without dojo.

Has anyone else tried this approach? Feedback welcome.

Regarding IRC - never used it myself - anyone?

Andy T


dojonewb wrote:

> seth lytle <srlytle.list <at> gmail.com> writes:
>
>  
>> i'll second james comment about knowing when it's ok to use the DOM
>> ... i'll usually check dojocampus, check quirksmode, maybe mumble
>> something on irc, check the dojo source for a place where it's doing
>> something similar. but figuring out what the "right" way of doing
>> something is a challenge. i'm in the process of trying to figure out
>> whether to use DOM methods or innerHTML for my content creation ...
>>    
>
> Wow, I have that same problem, even with whether to use javascript or dojo.  I
> thought it was because I was working my way
> through the russell book and after I'm done, I'd be all knowing and capable
> and stuff.  It's good to know I'm not the only one, this dojo thing is really
> difficult to learn.
> what's irc?  I've heard of it, but I"ve never used it.
>
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>  

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest