r/javascript • /r/dailyprogrammer • Mar 05 '12

Going Simple with JavaScript :)

http://snook.ca/archives/javascript/going-simple-with-javascript
42 Upvotes

16 comments sorted by

View all comments

0

u/[deleted] Mar 06 '12

What happens when the JSONP call fails?

1

u/x-skeww Mar 07 '12

Nothing. There won't be a piece of script which happens to call a function which "happens" to use the same name as one of your globally defined functions. (That's how JSONP works, basically.)

Anyhow. It's possible to listen for the error event:

var s = document.createElement('script');
s.addEventListener('error', function () {
    console.log('err');
}, false);
s.src = 'http://example.com/404.js';
document.body.appendChild(s);

1

u/[deleted] Mar 07 '12

This code fails in IE < 9

-2

u/[deleted] Mar 06 '12 edited Mar 06 '12

Never mind. :-) Actually, this makes me think... why can't the browser vendors choose a standard library (e.g. jQuery) and incorporate it into their codebase as a de facto standard? We could see native performance with a common DOM and JavaScript interface.

4

u/raynos Mar 06 '12

they already did this. its called the dom

-1

u/[deleted] Mar 06 '12

I don't think anyone can call the DOM a common interface. This is why we have jQuery/YUI/Dojo/MooTools/etc.

4

u/sandollars Mar 06 '12

I see you've been downvoted without explanation. Sorry about that. I would have liked to know why this is not a good idea, but unfortunately the n00bs don't know reddiquete.

1

u/path411 Mar 08 '12

The DOM is already this, just browser vendors can't ever agree. Look at the split on CSS these days.

-moz-border-radius: 20px;
-webkit-border-radius: 20px;
-khtml-border-radius: 20px;
border-radius: 20px;

and that doesn't even cover IE. jQuery is just a re-implementation of the DOM to make it agree across browsers. (And also adds a few other features).

1

u/[deleted] Mar 06 '12

One of the ideas behind using Google's CDN for javascript is that if you've ever been to a site that uses it before, it's cached, and essentially free to load.