Saturday, October 25, 2008

Fixing JSONP with CSS

I investigated several weeks ago to see if we can solve JSONP's flaw: Lack of error detection when the request does not arrive.

One possible new approach would use CSS as a carrier. There are two ways to import external CSS which a "csshttprequest" could exploit: <style/> (with @import rule) and <link/> to the URL. So far neither method works any better than JSONP.

The <link/> element does not provide an onerror event in DOM so it's impossible to detect loading errors.

The <style/> element DOES provide an onerror event but I can't for the life of me figure out a way to trigger that event! Does anyone know how/if it can be done?

If anyone figures out how to trigger an onerror event on a <style/> element they will essentially make cross site XHR exactly as powerful easy as traditional JSON.

No comments: