1

We have been working on a codeigniter hmvc project for quite sometime now and it has grown into a lot of back-end modules and controllers. For the front end we have been applying the regular jQuery and plugin approach along with inline scripting for Front end interaction and Ajax related tasks. Also we used HTML strings inside JS as our approach to templating.

But since now the application has gone big, we are in need to embrace the modular approach for our client side code along with implementing a build system for optimization of JS code. During our research we found a few candidates that would help us start managing the code. We zeroes in on requirejs for dependency management and for templating we are considering on out of handlebars/moustache/dust.js.

However, it seems like most of the applications using require and templating are based on backbone and are basically one page web apps. So, how do we implement the front end modularity and templating as a part of our already working (and growing) Codeigniter hmvc application ?

mlakhara
  • 235
  • 3
  • 11

1 Answers1

1

RequireJS is a good choice for managing your code base. It's hard to give good advice regarding other technologies, it depends on your preferred coding style, needs and JavaScript expertise.

Definitely compare different frameworks yourself and see which one is more comfortable. Some candidates include KnockoutJS, AngularJS, EmberJS.

And yes, you need to reference main.js in the data-main attribute of require.js script on every page (if you not creating single page app). Think of it as an entry point into your program.

Tomas Kirda
  • 8,347
  • 3
  • 31
  • 23
  • What does the main.js need to contain besides the config (path and shim). I can not write any application specific code in it as it is to be included in each page and thus the code is supposed to be different. Am I right? Would I need to write different main.js for each view? How should I go about integrating it in the present application? – mlakhara May 24 '13 at 15:56
  • Also will I be able to use the require optimizer in the build stages if I have different entry points? – mlakhara May 24 '13 at 15:57
  • It depends on your application architecture, whether to have single main.js or multiple. It doesn't have to be named main.js. There are definitely advantages having single main, and then have different logic based on what URL you are on. This way you have single build path. If you have different entry points you still can optimize for each build. But then those files are not cached and different file would be requested for each page. – Tomas Kirda May 24 '13 at 18:38
  • So can I include two scripts one main.js containing all the config ans shims. The second one with page specific application code.In the end I join all the app specific files to create one application file? – mlakhara May 25 '13 at 10:01