News for hackers. Stuff that matters.
Re:LightningJS: safe, fast, and asynchronous third-party Jav... by joshfraser on Wednesday October 26, 2011 @04:56AM (#3157692)
From the comments:

"The short answer is that the third-party provider must make small modifications to take advantage of LightningJS. This is done by adding the bootstrap Javascript and ensuring that the code uses window.parent for manipulation of the original document."

That's kinda a big asterisks to add. That said, deferring JS safely is really hard. It's not a bad thing for more people to be working on.

Re:LightningJS: safe, fast, and asynchronous third-party Jav... by mjpizz on Wednesday October 26, 2011 @10:32AM (#3158717)
I agree. LightningJS was originally written for third-party Javascript providers to improve their own embed code, though I think it would be awesome if end-users could easily take matters into their own hands. Maybe something for future development...
Re:LightningJS: safe, fast, and asynchronous third-party Jav... by iamleppert on Tuesday October 25, 2011 @05:58PM (#3156054)
I see you're creating an iframe and then loading the javascript script tag into the it. I assume this is how you are providing encapsulation of a unique window object per script. However, what about scripts that depend on access to the real window object?
Re:LightningJS: safe, fast, and asynchronous third-party Jav... by mjpizz on Tuesday October 25, 2011 @06:08PM (#3156084)
Good question. Since LightningJS writes the iframe with a "javascript:" URL, that iframe is really part of the same domain (and therefore same security context). To access the window on the original document, just use the "window.parent" object.
Re:LightningJS: safe, fast, and asynchronous third-party Jav... by izak30 on Tuesday October 25, 2011 @04:21PM (#3155711)
Did you guys look at caja? http://code.google.com/p/google-caja/
Re:LightningJS: safe, fast, and asynchronous third-party Jav... by mjpizz on Tuesday October 25, 2011 @04:48PM (#3155814)
I did just now :) The concepts in Caja are really interesting, but probably outside the scope of LightningJS. We used the term "safe" as in "safe from library conflicts", though I can see how that might have unintentionally indicated that it provides a managed sandbox as well.

That said, some kind of Caja integration could be a pretty nice addition to LightningJS.

Re:LightningJS: safe, fast, and asynchronous third-party Jav... by bcx on Tuesday October 25, 2011 @02:56PM (#3155359)
The funny thing is that this shows that Google Analytics's async loader can actually slows down window.onload in some cases.
Re:LightningJS: safe, fast, and asynchronous third-party Jav... by ghostwords on Tuesday October 25, 2011 @03:02PM (#3155386)
For a somewhat-related blast from the past, see Crockford's ADsafe:

http://www.adsafe.org/

Re:LightningJS: safe, fast, and asynchronous third-party Jav... by mjpizz on Tuesday October 25, 2011 @03:51PM (#3155587)
Haha, yea I remember that post. Good stuff. LightningJS is really more focused on being "safe" as in "no library conflicts", rather than sandboxing the code itself. In general, end users are copy/pasting embed code directly, so there wouldn't really be a guarantee that the third-party wrapped their resulting code in ADSafe :)

Definitely would be interesting to perhaps include some concepts from ADSafe into LightningJS though - maybe in the bootstrap component?

Re:LightningJS: safe, fast, and asynchronous third-party Jav... by bcx on Tuesday October 25, 2011 @03:19PM (#3155455)
That looks pretty interesting. I love the concept, I guess it just didn't really get the buy in that it needed.

Matt's loader is less focused on making javascript safe to embed from the security standpoint, and is more focused on ensuring that a 3rd part javascript file does not slow down your page.