简体   繁体   English

处理数据服务器端与客户端

[英]Processing data server-side vs client-side

I'm using PHP to pull financial data from yahoo. 我正在使用PHP从雅虎提取财务数据。 Then I'm sending the data in JSON format to one of my Typepad blogs and receiving it with JavaScript. 然后我将JSON格式的数据发送到我的一个Typepad博客并使用JavaScript接收它。

Is it faster to process the data on the server-side, then send the JSON subset to JavaScript. 在服务器端处理数据是否更快,然后将JSON子集发送到JavaScript。 Or would it be better to send the whole thing, then process it with JavaScript on the client side? 或者发送整个内容,然后在客户端使用JavaScript处理它会更好吗?

How do I learn how to make this type of trade-off analysis on my own? 我如何自己学习如何进行这种权衡分析?

Mostly good estimating. 非常好估计。 Sending large amounts of data to the client for processing will incur client overhead and make their browsing experience less acceptable. 将大量数据发送到客户端进行处理会导致客户端开销,并使其浏览体验难以接受。 Processing data server side will increase your server load per client. 处理数据服务器端将增加每个客户端的服务器负载。

This is a common situation seen with large tables of data that are sortable or paginated. 这是可以排序或分页的大型数据表中常见的情况。 You can either do that entirely in browser or enable server side sorting and paignation. 您可以在浏览器中完全执行此操作,也可以启用服务器端排序和paignation。 My rule of thumb is if I have more then 10k cells (10 columns x 1000 rows) then I should probably enable server side processing instead of leaving it up to the client. 我的经验法则是,如果我有超过10k的单元格(10列x 1000行),那么我应该启用服务器端处理而不是将其留给客户端。 This is especially true on older machines with shitty slow JavaScript engines. 在具有 糟糕的 慢速JavaScript引擎的旧机器上尤其如此。

I find it safe to assume that my clients would have the shittiest computer, and making them do processing is not really what I want. 我觉得可以安全地假设我的客户会拥有最糟糕的计算机,并让他们进行处理并不是我想要的。 So I mostly do server-side processing - unless it's really basic stuff like simple sorting etc etc. 所以我主要做服务器端处理 - 除非它是真正基本的东西,如简单的排序等。

Also, don't assume JavaScript is enabled. 此外,不要假设启用了JavaScript。 You have to fall back gracefully and that would require the server to do the processing anyhow. 您必须优雅地退回,这将要求服务器无论如何都要进行处理。

Well, it depends. 这得看情况。 If you process the data server side, you'll have to wait for return from Yahoo! 如果你处理数据服务器端,你将不得不等待从Yahoo!返回 and then output the resulted JSON and HTML page. 然后输出生成的JSON和HTML页面。

If you process the data on the client side (ie you make requests with javascript) you'll have loaded page and you can give the user some kind of notification, that the data is loading. 如果您在客户端处理数据(即您使用javascript发出请求),您将加载页面,并且您可以向用户提供某种通知,即数据正在加载。

About that which will be faster - better run some tests. 关于那将更快 - 更好地运行一些测试。 It's the best way to see :) 这是最好的方式来看:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM