Better MVC approach for web application development-用MVC方式改进Web应用程序开发
Typical web development mixes HTML content and server side code and allows dynamic content to be generated in server side. Both .NET and Java made web development easier by using server side controls (ASP.NET server controls and JSF). However the typical web development approaches have some major drawbacks:
经典Web开发中一般混合了HTML与服务器端代码,并允许服务器端动态生成各种内容数据。.Net与Java通过一系列的服务器控件(例如,ASP.NET服务器控件和Java的JSF)大大简化了Web开发。虽然如此,经典Web开发方法还是有一些至命弊端:
1.Mix HTML code and server side code, make it difficult to read, write, and maintain the code.
2.Make it hard to take advantage of full power of HTML/JavaScript, especially when HTML5 is better supported now.
3.Hard to test, have to redeploy code, hard to isolate issues in client side code (HTML/JavaScript) and server side code
4.Have a lot overhead in server side processing, increase network traffic with un-necessary trips to server and un-necessary data exchange.
5.Lock to specific technology/language, hard to share code cross multiple platforms.
An alternative web development approach can help resolve above issues and make it much easier to build highly interactive web application:
1.Use pure HTML/JavaScript to build user interface, can use library like jQuery to make development easier. Whole UI can be developed as local HTML files and tested directly in browser without web server.
2.Only data will be loaded from server program using either JSON or XML format, UI code will be independent of server side technology/language.
3.UI will load data through AJAX call and then do all dynamic UI change in client side with pure HTML/JavaScript (refresh UI with new data, sort data, search within local data, etc.). UI can be tested without server side code --- AJAX call can load test data from a local file as text file, UI can be fully tested as long as local data file has similar data as what will be returned by server side code.
4.Front controller and data modeling can be used in server side development to make development easier; a central front controller can be used for security control, log, etc. Utility function can be used to automatically convert data model to JSON/XML format (template based processing can further decouple data from return format )
Benefits of the new approach:
1.Much easier to develop highly interactive user interface, separate front end design from server side development, allow both sides to be developed/tested parallelly.
2.Much easier for testing, both client side and server side can be tested independently. Client side can be tested locally with local data files (once server is ready, can easily switch local URL to real server URL); server can be tested/verified without UI and can also be easily automated.
3.Much smaller overhead in server side process, can significantly reduce traffic to server and reduce network bandwidth usage
4.UI independent of server side technology/language, server side code can be shared for all platforms (web, desktop, mobile), since it contains pure data, no UI/platform specific information.