Approach to handle javascript on bigger projects?

后端 未结 4 883
误落风尘
误落风尘 2021-01-31 06:18

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 increas

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 06:56

    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.

提交回复
热议问题