mozilla/browserid — pull request #3590 by 6a68 (2013-06-27 19:07:16+00:00)
Title: Async snippet 2

@shane-tomlinson mind taking a look? I could use some feedback.

#### Summary

This is a more well-rounded successor to the async snippet prototype I started last week (#3547). Seeking feedback.

#### Next Steps

If this looks good, I think the next step would be to create some RP integration docs (blog post and/or MDN page), and *maybe* create a separate local testing example RP. Does this seem reasonable? Thoughts?

#### Background

We're in a bit of an awkward position relative to your typical third-party provider because we are shimming browser APIs, so our async snippet really does want to set global state. So, an async Persona snippet needs two parts: (1) something in the head that stubs out nav.id.* before the script has loaded and sets up queues to collect function calls, and (2) the usual async snippet which builds a script tag, appends to the page, then unqueues waiting function calls when the script is ready.

This two-part thing seems complicated for a typical RP to have to integrate. I'm not sure.

The alternative I can think of is to put both parts of the snippet in the head, and wrap part (2) in a window.onload handler. This would also give additional flexibility, since the listener could be configured to listen for custom events--if the RP wanted to load some of their content scripts, and then fire nav.id.watch, for instance.