severside处理VS客户端处理+ AJAX? [英] severside processing vs client side processing + ajax?

查看:128
本文介绍了severside处理VS客户端处理+ AJAX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一些一般性的建议和/或想法......

looking for some general advice and/or thoughts...

我要创建什么,我觉得更多的是Web应用程序,然后网页,因为我想让它像Gmail应用程序,你会整天在获取更新推到页面离开页面打开(有兴趣的我使用彗星编程技术)。我从来没有创建了一个网页,在此之前,有这么丰富的Ajax和JavaScript(我现在是jQuery的一个巨大的风扇)。正因为如此,一次又一次,当我实现一个新功能,需要在服务器需要知道,我面临着同样的问题UI中的动态变化:

i'm creating what i think to be more of a web application then web page, because i intend it to be like a gmail app where you would leave the page open all day long while getting updates "pushed" to the page (for the interested i'm using the comet programming technique). i've never created a web page before that was so rich in ajax and javascript (i am now a huge fan of jquery). because of this, time and time again when i'm implementing a new feature that requires a dynamic change in the UI that the server needs to know about, i am faced with the same question:

1)我应该做的所有的处理JavaScript中的客户端和后背部尽量少通过ajax 要么 2)我应该发布一个请求通过AJAX服务器,让服务器完成所有的处理,然后发回新的HTML。然后在Ajax响应我做了新的HTML一个简单的赋值

1) should i do all the processing on the client in javascript and post back as little as possible via ajax or 2) should i post a request to the server via ajax, have the server do all the processing and then send back the new html. then on the ajax response i do a simple assignment with the new HTML

我一直倾向于始终遵循#1。这个Web应用程序我想可能会得到pretty的健谈与所有的Ajax请求。我的想法是尽量减少尽可能多的请求和响应的大小,并依靠不断改进的JavaScript引擎做尽可能多的处理和用户界面的更新成为可能。我发现使用jQuery我可以做在客户端,我不会已经能够做之前很容易这么多。我的javascript code其实是更大的,比我的服务器端code更复杂。也有简单的calulcations我需要执行,我已经推了在客户端了。

i have been inclined to always follow #1. this web app i imagine may get pretty chatty with all the ajax requests. my thought is minimize as much as possible the size of the requests and responses, and rely on the continuously improving javascript engines to do as much of the processing and UI updates as possible. i've discovered with jquery i can do so much on the client side that i wouldn't have been able to do very easily before. my javascript code is actually much bigger and more complex than my serverside code. there are also simple calulcations i need to perform and i've pushed that on the client side, too.

我想主要的问题我已经是,我们应该始终追求的客户端处理过服务器端的处理只要有可能?我一直觉得少了服务器处理的可扩展性/性能越好。让客户端的处理器的能力做所有的辛勤工作(如果可能)。

i guess the main question i have is, should we ALWAYS strive for client side processing over server side processing whenever possible? i 've always felt the less the server has to handle the better for scalability/performance. let the power of the client's processor do all the hard work (if possible).

想法?

推荐答案

我同意你的看法。推尽可能给用户,但不会太大。如果您的应用程序变慢,或更糟糕的崩溃浏览器,你松。

I agree with you. Push as much as possible to users, but not too much. If your app slows or even worse crashes their browser you loose.

我的建议是实际测试你如何应用程序的行为时,接通一整天。检查有没有内存泄漏。检查没有一个Ajax请求创建第二个的每个半与应用程序一段时间工作后,(在JS定时器可以是一个痛苦的某个时候)。

My advice is to actually test how you application acts when turned on for all day. Check that there are no memory leaks. Check that there isn't a ajax request created every half of second after working with application for a while (timers in JS can be a pain sometime).

除此之外,从不与JavaScript的执行用户输入验证。总是重复它在服务器上。

Apart from that never perform user input validation with javascript. Always duplicate it on server.

修改

使用jQuery的活结合。重新绑定生成的内容,将让你的架构更加清晰时,它会为你节省大量的时间。可悲的是,当我正在开发用jQuery是尚未公布;我们使用其他工具与相同的效果。

Use jquery live binding. It will save you a lot of time when rebinding generated content and will make your architecture more clear. Sadly when I was developing with jQuery it wasn't available yet; we used other tools with same effect.

在过去,我也有一个问题,当一个网页的一部分代用ajax依赖于另一部分产生。产生第一部分的第一和第二部分第二会使你的网页速度较慢预期。在前面这个计划。开发一个网页,使他们已经打开时拥有的所有内容。

In past I also had a problem when one page part generation using ajax depends on other part generation. Generating first part first and second part second will make your page slower as expected. Plan this in front. Develop a pages so that they already have all content when opened.

另外(对于简单的网页也是如此),让一台服务器上的低引用的文件的数量。加入JavaScript和CSS库到服务器端一个文件。保持单独的主机,更独立的主机(创建只是一个三级域名将做太多)上的图像。虽然这是值得的,只有在生产;它会使开发过程更加困难。

Also (regarding simple pages too), keep number of referenced files on one server low. Join javascript and css libraries into one file on server side. Keep images on separate host, better separate hosts (creating just a third level domain will do too). Though this is worth it only on production; it will make development process more difficult.

这篇关于severside处理VS客户端处理+ AJAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆