BoilerplateMVC / Backbone-Require-Boilerplate

A Rad Backbone.js and Require.js Boilerplate Project.
MIT License
604 stars 129 forks source link

Query about Requiring non-needed dependancies #6

Closed Integralist closed 12 years ago

Integralist commented 12 years ago

Heya,

Just having a quick read through your JavaScript code and was a bit confused by why you're specifying dependencies unnecessarily (as far as I'm aware it's unnecessary).

For example, in both js/desktop.js and js/mobile.js you have something like...

require(['modernizr','jquery','backbone','routers/desktopRouter','bootstrap','backbone.validateAll'], function(Modernizr, $, Backbone, Desktop) {

    // Instantiates a new Router
    this.router = new Desktop();
});

...but you only utilise the routers/desktopRouter' dependency but you're specifying jQuery and Backbone. You're specifying both of those as dependencies within routers/desktopRouter' which is fine because that's exactly what they are, but it doesn't make sense to me to have them specified in the top level script file if they're not actually used in that require callback?

It's not an error as such, and doesn't make any real difference from a performance point of view as all dependencies are only ever loaded once by RequireJS, but just seemed like your code could be simplified if you left those dependencies out until actually needed.

Ps, on a side note (sorry if you would prefer this to be a separate issue but I assumed it would be easier to just quickly mention this here) - is there any reason for the mobile variation why you're not swapping out jQuery for ZeptoJs (which is better geared for mobile development). Again, what you've done isn't wrong as it depends on your requirements, but I know people have issue with loading something like jQuery on a mobile device when something smaller like ZeptoJs (which is supposed to be jQuery API compatible) could be used. But ZeptoJs only works on Android 2.2+ and iOS 4+ so that in itself might be a reason not to use it.

gfranko commented 12 years ago

@Integralist Good point, those script includes are unnecessary. I believe I left them in for convention (so anyone reading the code could see which 3rd party scripts I was using). I'll remove them in the next version of BRB.

Regarding jQuery being used instead of Zepto.js... considering that jQuery now offers custom builds, I don't believe file size is too much of an issue. If you wanted to, you could easily create a custom jQuery build that only offers DOM and Ajax methods.

Integralist commented 12 years ago

@gfranko that's fine, as I mentioned: none of it's wrong, just depends on your requirements. Also just to elaborate on the Zepto thing: jQuery has lots of IE specific code which is redundant for majority of mobiles that aren't Windows based, something Zepto doesn't suffer from. So although jQuery offers modular builds, things like their DOM API code base is still chock full of IE related bugs/fixes. So probably worth you investigating Zepto further :-)

gfranko commented 12 years ago

Yea I will definitely look deeper into Zepto. I know that jQuery 2.0 and above will no longer support IE 6-8 (jQuery 1.9 will continue to), but until then Zepto might be a good option.