InboxSDK.loadScript method issue

128 views
Skip to first unread message

Dimu Designs

unread,
Dec 20, 2016, 9:07:54 PM12/20/16
to InboxSDK
I've have a number of scripts I need to load into my extension. I'm leveraging a library (CryptoJS) that is comprised of several components (individual javascript files) that I'd like to swap in and out to test various features. The library has dependencies between its core component scripts and those that can be plugged in/out; thus I have written code to load in the core components in their entirety before loading the plugins (and I've verified this via the timeline in Dev Tools). However I keep getting a Reference Error stating that the core Module (CryptoJS) is not defined. 
I invoke the InboxSDK.loadScript method for each individual script and I assume that they are all loaded into the same scope. Am I wrong in that assumption? I suppose I could concatenate the scripts into one file but I'd like to avoid that.

er...@streak.com

unread,
Feb 21, 2017, 7:21:02 PM2/21/17
to InboxSDK
By default loadScript does load each file in it's own scope, so if you're relying on a shared variable scope it most likely will not work. If you really need to share scope between files you'd most likely have to use window.* globals.

Stepping back for a second though, why do you want to avoid concatenating your JS files? I understand the desire to swap out individual modules to try things out in development, but if you are using any of the popular tools for managing JS modules & concatenating/packaging/etc. they should theoretically allow you to do a convenient swap of a module on your machine while developing. On the production side (i.e. when you actually ship your code to users), I highly recommend considering concatenation if you aren't already doing so. Each additional JS file you load carries an extra performance cost, and depending on how many files you're loading that cost could be significant.
Reply all
Reply to author
Forward
0 new messages