Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The big piece missing from this is RequireJs as the author mentions. We should all know it's good practice not to use global variables so that should be reason enough to use it in itself.

As an example an app we built had a conflict between a jQuery plugin that the frontend devs had included, and a library that we had added with require. Having the conflict only show up in one place rather than the whole app certainly made it quicker to diagnose.

Addy Osmani's tutorials should be required reading if you're just starting out. [1] [2]

The only downside that we saw was that you will have to provide AMD versions of each library you use if you want to use jQuery from a CDN.

As well as being good practice it just feels really nice to have everything you're using declared at the top of the file you're in. The sugared require syntax helps with this. [3]

[1] https://github.com/addyosmani/backbone-fundamentals

[2] http://addyosmani.com/largescalejavascript

[3] http://requirejs.org/docs/whyamd.html#sugar



If you find RequireJS a bit too intrusive you could check out a dependency manager I wrote: https://github.com/judofyr/dep.js

It's tiny (411 bytes minified; 268 bytes gzipped) and only handles dependency management. It's excellent if you just want to avoid worrying about the order you concatenate your files, but it's also possible write a basic RequireJS-style script-loader on top of it.


I have found it is convenient to use RequireJS's shim features to load libraries that use AMD rather than looking for AMD versions. For example, we use MathJax off their CDN and they do not provide an AMD version.


Are you using the r.js optimiser though? We definitely couldn't use a local non-AMD version with other CDN libraries when using the optimiser to build our js out for production.


AMD is a pain to use , and make the code really ugly. It has some compatibility issues with some older (but widely deployed ) mobile browsers and doesnt really fix javascript shortcomings. You can still have global variables into a module anyway. And a lot of libraries dont even support AMD , why should they ?


It's a pain because some libs support AMD and some don't, but it's the least bad solution that I know of. If there's a better option I'm all ears.

Of course you can add a global variable in a module if you want to, but 1. why would you? and 2. If this happens by accident it should be picked up by a linter.

Which mobile browsers have issues? Would be good to know.


browserify




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: