0
votes

I am starting my project structure from scratch. I am using require.js, backbone, underscore, bootstrap, etc. I was thinking to use shim config to load non AMD compatible of backbone, underscore,etc. But, now, i think its better to use AMD (Asynchronous Module Definition) compatible version of them since it allows to load parallely the resources. But, where can i find reliable source for AMD compatible underscore, backbone and bootstrap? And can i be assured that I will alz get latest version of backbone, bootstrap and underscore AMD compatble version. Will they cause any break later?

In word, can anyone suggest me to use AMD Compatible version of them or tade off to use shim config to load non-amd version of them against loading time. I am planning to use require-jquery AMD.

3
Are you referring to Node.js or are you doing this stuff client side?Matt
@Matt on client side for developing mobile phonegap applcationsuser2314342
I guess I am unaware of such a thing. Its all javascript right? I don't think there is a processor specific implementation of those libraries since they are all scripting languages and compiled on the fly.Matt
yes, they all are scripting language.user2314342
Ahhh AMD != Advanced Micro Devices.... I don't know much about Asynchronous Module DefinitionMatt

3 Answers

1
votes

I can only provide one point of view, but from my experience, at this stage, it's better just to shim the dependencies. I don't feel that amd is widely adopted enough yet to get the kind of support you'll need to make everything work nicely together using the amd versions.

In particular, I had a problem with testing (Jasmine), where my Jasmine tests would be referring to one "jQuery" and my application code would be referring to another one, because neither were globals. I just gave up and switched back to using shims, and managed to get the tests to work (although not without some work).

Not sure if it will help, but here are my personal notes on integrating RequireJS into a BackboneJS/Rails stack. The section on stubbing dependencies might be of interest if you'll be testing your client-side code. I hit quite a few snags along the way...

1
votes

Yes, it is better. I can say that after developing largescale apps with require and backbone - they work great together. Use a build process that uses r.js to boil your app js down to a single file so there isn't a dependency on production obviously. We have had no problems integrating this with jasmine as a unit tester in response to the answer above (not that I would personally bother with unit testing, stick with behavioural testing instead).

This is a good starting point for getting an idea of how it fits together: http://net.tutsplus.com/tutorials/javascript-ajax/a-requirejs-backbone-and-bower-starter-template/

Though consider jam as a package manager or none at all, and grunt to create build tasks etc but still useful just don't treat stuff as gospel try it yourself!

1
votes

Personally I don't think using AMD version library is better. Because 1. rely on community to maintain the AMD version 2. use shim and export the global is better 3. you cannot expect all libraries have AMD version

I have spent hours dig bugging why the optimizely code via rjs says that Backbone is not found and had to remove some code in the backbone source to make it works.

In short, use shim.