Multiple bundles with cram & curl

33 views
Skip to first unread message

Chris Hafey

unread,
Jan 17, 2014, 9:27:39 AM1/17/14
to cuj...@googlegroups.com

Hi, 
  I am prototyping a curl + cram application and would like to break the application into multiple bundles.  There would be an initial bootstrap bundle which would contain shared code and then based on what the user does, would load other dynamic bundles on the fly.  Think about a rarely used dialog that has js, css and html in it.  I would put that in its own dynamic bundle and load it "on demand" making the user pay the cost only when they need to.  There could be multiple such dynamic bundles that could be loaded.  I have this sort of working now like this:

My bootstrap bundle references all shared code and plugins that the dynamic bundles might reference. 

Dynamic bundles are built with cram by specifying the root javascript file using --include and using --exclude to exclude the shared javascript modules that are already loaded in the bootstrap bundle.  Cram produces a single file with a bunch of define() blocks in it.  

When I want to load the dynamic module, I use curl and the js plugin to load the dynamic module.  Once the js is loaded, I can use curl again to access any module from the dynamic bundle since they are now loaded.

So this seems to be working with one small problem - the js plugin gets loaded a second time when the dynamic bundle is loaded even though it is referenced by the bootstrap bundle.  I can actually live with this extra cost but I would like to have it work perfectly if I can.  So a few questions for the group:

1) Any thoughts/feedback on my strategy above?  
2) Any thoughts on why the js plugin gets loaded a second time?  Any tips/pointers for me to debug/fix this would be great.

Thanks for any help!

Chris Hafey

PS - It looks excludes is currently broken in cram (e.g. --exclude Foo.js will cause it to crash).  I am working around this by using a json config object that looks like this:

{
    "excludes" : {
        "Foo" : true
    }
}

Chris Hafey

unread,
Jan 17, 2014, 4:21:20 PM1/17/14
to cuj...@googlegroups.com
I have a workaround for #2 - I am now including the js plugin via a json config file when I build the bootstrap bundle.  What didn't work is including the file using the --include option (it got the module id wrong) or by using the js plugin in the bootstrap module itself (cram doesn't include the js plugin but instead inlines the resource automagically).  

unscriptable

unread,
Jan 21, 2014, 2:55:54 PM1/21/14
to cuj...@googlegroups.com
Hey Chris,

Very excited to see you using multiple bundles. :)

In regards to your strategy (#1), I was surprised to see you use the js! plugin to load the bundles.  I see how that this would work, but it never occurred to me to do it this way!  

Here's another way.  If your bundle has a "main" module (really, any primary entry point that is a module), then you could map a path or package from the main module's id to the bundle' url and `require(theMainModule);`.

Regarding #2, we are aware that plugins do not get bundled.  This is by design -- although on more than one occasion we've had to --include run-time plugins, as well.  The motivation for not including run-time plugins is that, normally, the build-time plugins eliminate the need for load-time plugins since the resources are embedded. We're open to suggestions if you have any ideas how to make this more intuitive or seamless! :)

Glossary: run-time plugin === curl plugin.  build-time plugin === cram plugin :)

Regarding the crash, please check the latest cram.js.  We made some updates recently that might affect this functionality.  If you still experience the crash, please open a github issue!  Thanks!

Regards,

-- John
Reply all
Reply to author
Forward
0 new messages