Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Approach to handle javascript on bigger projects?

After discovering jQuery a few years ago, I realized how easy it was to really make interactive and user friendly websites without writing books of code. As the projects increased in size, so did also the time required to carry out any debugging or perhaps implementing a change or new feature.

From reading various blogs and staying somewhat updated, I've read about libraries similar to Backbone.js and JavascriptMVC which both sound like good alternatives in order to make the code more modular and separated.

However as being far from an Javascript or jQuery expert, I am not really not suited to tell what's a good cornerstone in a project where future ease of maintainability, debugging and development are prioritized.

So with this in mind - what's common sense when starting a project where Javascript and jQuery stands for the majority of the user experience and data presentation to the user?

Thanks a lot

like image 647
Industrial Avatar asked Feb 23 '11 18:02

Industrial


People also ask

What is an example of a best practice for using JavaScript in your project?

Modularize — one function per task This is a general programming best practice — making sure that you create functions that fulfill one job at a time makes it easy for other developers to debug and change your code without having to scan through all the code to work out what code block performs what function.

What are the problems with JavaScript?

These days, most cross-browser JavaScript problems are seen: When poor-quality browser-sniffing code, feature-detection code, and vendor prefix usage block browsers from running code they could otherwise use just fine. When developers make use of new/nascent JavaScript features, modern Web APIs, etc.)


1 Answers

Both Backbone.js and JavascriptMVC are great examples of using a framework to organize large projects in a sane way (SproutCore and Cappuccino are nice too). I definitely suggest you choose a standard way of deal with data from the server, handling events from the DOM and responses from the sever, and view creation. Otherwise it can be a maintenance nightmare.

Beyond an MVC framework, you should probably choose a solution for these problems:

  • Dependency management: how will you compile and load javascript files in the right order? My suggestion would be RequireJS.
  • Testing: testing UI code is never easy but the guys over at jQuery have been doing for a while and their testing tool QUnit is well documented/tested.
  • Minification: you'll want to minify your code before deploying to production RequireJS has this built in but you could also use the Closure Compiler if you want to get crazy small source.
  • Build System: All these tools are great but you should pull them all together in one master build system so you can run a simple command on the commandline and have you debug or production application. The specific tool to use depends on your language of choice - Ruby => Rake, Python -> Write your own, NodeJS as a build tool (i like this option the most) -> Jake

Beyond that just be aware if something feels clunky or slow (either tooling or framework) and refactor.

like image 132
Shakakai Avatar answered Nov 15 '22 23:11

Shakakai