Loading brassmonkey.js asynchronously

8 views
Skip to first unread message

Dobes Vandermeer

unread,
Aug 9, 2013, 7:17:59 PM8/9/13
to brassmo...@googlegroups.com
I tried to load the SDK asynchronously as part of my game engine's script loading framework and it didn't work out for various reasons.  Something to consider for the future would be supporting asynchronous loading.

Francois Laberge

unread,
Aug 9, 2013, 9:19:33 PM8/9/13
to brassmo...@googlegroups.com, brassmo...@googlegroups.com
Good idea. I've made modifications before to support it. 

Adding it to my TODO.

Sent from my iPhone

On 2013-08-09, at 6:17 PM, Dobes Vandermeer <dob...@gmail.com> wrote:

I tried to load the SDK asynchronously as part of my game engine's script loading framework and it didn't work out for various reasons.  Something to consider for the future would be supporting asynchronous loading.

--
 
---
You received this message because you are subscribed to the Google Groups "Brass Monkey SDK" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brassmonkey-s...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Francois Laberge

unread,
Aug 9, 2013, 9:22:27 PM8/9/13
to brassmo...@googlegroups.com, brassmo...@googlegroups.com
Are you using RequireJS or another module loader? Or something custom?

Sent from my iPhone

On 2013-08-09, at 6:17 PM, Dobes Vandermeer <dob...@gmail.com> wrote:

I tried to load the SDK asynchronously as part of my game engine's script loading framework and it didn't work out for various reasons.  Something to consider for the future would be supporting asynchronous loading.

Dobes Vandermeer

unread,
Aug 12, 2013, 4:52:11 PM8/12/13
to brassmo...@googlegroups.com
I'm using the playcraft SDK, they have their own asynchronous loader system.

Francois Laberge

unread,
Aug 12, 2013, 5:06:24 PM8/12/13
to brassmo...@googlegroups.com
Anything I can do to help make it work asynchronously? Looking at their site, it seems only a small part of their system is open sourced. I can pretty easily modify the SDK to work with a particular module loader pattern. Any idea which approach they are taking? AMD style?

Francois
Francois Laberge
CTO
Brass Monkey Inc.
San Francisco | Boston

Dobes Vandermeer

unread,
Aug 12, 2013, 6:34:46 PM8/12/13
to brassmo...@googlegroups.com
Hi Francois,

The main problem I ran into is that the code expects a certain sequence of events:
  1. Load BM script (sets up window.bm and registers onload handler)
  2. Call bm.init() (in a script tag)
  3. onload event fires and creates BM elements and does other BM setup
The problems I ran into were:
  1. If I haven't called bm.init() before onload fires, for example, it runs into some problems with undefined values.
  2. If I load the script AFTER onload has already fired, it never fires the onload event and finishes the BM setup
The most flexible approach would probably be to have it so that the onload handler does nothing if it was previously already run or bm.init() was not called, and then have bm.init() do that onload work if it's called after the page has already loaded.  You can check if the page has loaded using document.readystate I believe.

The code could be super-async if you don't realy on bm being present before calling bm.init, you can take a look at how google analytics does this for an example.  Not useful in my case, however, I can know that the brassmonkey js is loaded AND the DOM is loaded when I call bm.init().

If I had the original sources I could probably stick this logic in there myself...

Cheers,

Dobes



Reply all
Reply to author
Forward
0 new messages