客户端还是服务器端处理? [英] Client-side or server-side processing?

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

问题描述

所以,我是新来的动态网页设计(我的网站大部分是静态使用一些PHP),我正在尝试学习网页开发中最新的技术(这似乎是AJAX),而且我在想如果您传输大量数据,最好在服务器上构建页面并将其推送给用户,或者最好是拉所需的数据,并在客户端周围创建HTML使用JavaScript?



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



感谢您的帮助

解决方案

恭喜您移动到动态网站!我会说,您需要满足以下条件来进行客户端布局(不用说您应该始终执行过滤DB查询和控制访问权限服务器端):




  • 绝大多数使用情况下,客户端浏览器和连接功能都可以触发。

  • SEO和移动/旧版浏览器退化不一个很大的问题(当您合成HTML服务器端时,更容易)



即使这样,客户端布局也使得测试变得更加困难。它也产生相当麻烦的同步问题。如果一个AJAX网站加载了部分内容,那么如果页面的某些部分被拧紧,您可能永远都不会知道,但是通常是服务器端的组合,整个页面会在每个请求上重新加载。它还为错误/超时处理,会话/ cookie处理,缓存和导航(浏览器返回/转发)增加了额外的挑战。



最后,生产更难如果有人想与他们的朋友分享一个链接,或者为自己添加一个链接,则会使用perma-URL。我在我的博客文章这里中解决了一个解决方法,或者你可以有一个突出的总而言之,特别是在开始的时候,我会说更多的犹太人,更好的支持,更多的辅导,传统的方法将HTML服务器端放在一起。然后在这里和那里蘸一些AJAX(也许从表单验证或自动完成开始),然后继续上去。



祝你好运!


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?

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...

Thanks for the help

解决方案

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):

  • Client browser and connection capabilities are up to snuff for the vast majority of use cases
  • SEO and mobile/legacy browser degradation are not a big concern (much easier when you synthesize HTML server side)

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).

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.

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.

Good luck!

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

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