客户端还是服务器端处理?

客户端还是服务器端处理?

问题描述:

所以,我是新的动态网页设计(我的网站大多是静态的一些PHP),我试图学习最新的技术在Web开发(这似乎是AJAX),我想知道,如果你要传输大量数据,最好是在服务器上构建页面并将其推送给用户,或者最好拉所需的数据并在客户端上创建HTML使用JavaScript?

So, I'm new to dynamic web design (my sites have been mostly static with some PHP), and I'm trying to learn the latest technologies in web development (which seems to be AJAX), and I was wondering, if you're transferring a lot of data, is it better to construct the page on the server and "push" it to the user, or is it better to "pull" the data needed and create the HTML around it on the clientside using JavaScript?

更具体地说,我使用CodeIgniter作为我的PHP框架,jQuery用于JavaScript,如果我想显示一个数据表给用户动态),最好是使用CodeIgniter格式化HTML(创建表,向元素添加CSS类等),或者更好的方法是使用JSON提供原始数据,然后将其构建到表中jQuery?我的直觉说,做客户端,因为它可以节省带宽,页面可能会加快更快的新的JavaScript优化所有这些浏览器现在,然而,该网站会打破不使用JavaScript的人...

More specifically, I'm using CodeIgniter as my PHP framework, and jQuery for JavaScript, and if I wanted to display a table of data to the user (dynamically), would it be better to format the HTML using CodeIgniter (create the tables, add CSS classes to elements, etc..), or would it be better to just serve the raw data using JSON and then build it into a table with jQuery? My intuition says to do it clientside, as it would save bandwidth and the page would probably load quicker with the new JavaScript optimizations all these browsers have now, however, then the site would break for someone not using JavaScript...

感谢您的帮助

我想说,以下条件必须满足你做客户端布局(不言而喻,你应该总是做类似于过滤DB查询和控制访问权限服务器端):

Congratulations for moving to dynamic sites! I would say the following conditions have to be met for you to do client-side layout (it goes without saying that you should always be doing things like filtering DB queries and controlling access rights server side):


  • 客户端浏览器和连接功能对于绝大多数用户来说都达到了极限。

  • SEO和移动/一个大问题(当您合成HTML服务器端时更容易)

即使如此,做客户端布局也使测试更难。它也产生相当麻烦的同步问题。使用AJAX网站加载partials,如果页面的一部分拧紧,你可能永远不知道,但使用常规的服务器端组合,整个页面重新加载在每个请求。它还给错误/超时处理,会话/ cookie处理,缓存和导航(浏览器回退/转发)带来了额外的挑战。

Even then, doing client-side layout makes testing a lot harder. It also produces rather troublesome synchronization issues. With an AJAX site that loads partials, if part of the page screws up, you might never know, but with regular server-side composition, the entire page is reloaded on every request. It also adds additional challenges to error/timeout handling, session/cookie handling, caching, and navigation (browser back/forward).

最后, perma-URL,以防有人想与他们的朋友分享链接或为自己添加链接。我在我的博客帖子此处处理了一个解决方法,或者您可以有一个突出的

Finally, it's a bit harder to produce perma-URLs in case someone wants to share a link with their friends or bookmark a link for themselves. I go over a workaround in my blog post here, or you can have a prominent "permalink" button that displays a dynamically rendered permalink.

总体来说,特别是开始时,我会说更多的犹太教,更好的支持,更多的教学,传统的方法将HTML服务器端整合在一起。

Overall, especially when starting out, I would say go with the more kosher, better supported, more tutorialed, traditional approach of putting together the HTML server side. Then dip in some AJAX here and there (maybe start out with form validation or auto-completion), and then move on up.

祝你好运!