服务器端与客户端(AJAX)正在加载 [英] Server-side vs. Client-side (AJAX) Loading

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

问题描述

我想知道什么是最好的做法。比方说,我有一个下拉选择窗口小部件。它应该是ploaded与页面时从服务器提供,或一旦它被加载,如果一个AJAX请求进行检索的内容,然后填充它的内容$ P $?

I was wondering what is considered best practice. Let's say I have a dropdown select widget. Should it be preloaded with content when the page is served up from the server or once it is loaded, should an AJAX request be made to retrieve the contents and then populate it?

我还挺喜欢加载空并发出一个AJAX调用来检索内容的想法。但是,这是将导致较慢的页面加载时间。尤其如果页面需要下载从服务器内容几个部件?

I kinda like the idea of loading it empty and issuing an AJAX call to retrieve the contents. But is that going to result in slower page loading times. Especially if the page has several widgets that need to be loaded with content from the server?

它的问题就被加载的内容量?

Does it matter on the amount of content being loaded?

有关下拉例如,我的意思是,在下拉菜单中的选项。所以,如果我有员工的下拉菜单选择,从我指的是员工的名单。难道我打开一个空的下拉列表,并在控制器上有它检索员工和填充下拉的初始化?

For the dropdown example, I meant the options in the dropdown. So if I had a dropdown of employees to choose, from I am referring to that list of employees. Do I load an empty dropdown and on init of the controller have it retrieve the employees and populate the dropdown?

但后来我想想,让我们说200行就业者,并存储在一个数据库中的一些员工数据的数据网格。难道我加载页面,在页面加载时有一个控制器的初始化函数获取员工和填充的数据集,并显示数据网格?

But then I think about a datagrid of let's say 200 rows of emplyees and some employee data that is stored in a database. Do I load the page and when the page loads have a controller whose init function retrieves the dataset of employees and populates and displays the datagrid?

或者,当页面被从服务器它检索服务器端它也创造DataGrid中的数据集,它被装呢。 这是编程的世界,我习惯了在过去已经做主要PHP,JSP和ASP的东西。只有使用JavaScript的一些很酷的翻页效果,等等。

Or when the page is served up from the server does it retrieve the dataset on the server-side where it also creates the datagrid and it gets loaded then. This is the programming world that I am used to having done mostly PHP, JSP and ASP stuff in the past. Only using JavaScript for some cool page effects, etc.

不过,我似乎喜欢,一旦页面加载(或正在加载)的想法,使AJAX请求来检索以填充当前屏幕上的小部件/内容所需的数据。我只是担心,页面加载可能看起来笨拙或缓慢的,因为我现在正在做更多的请求到服务器来绘制页面。页面的初始请求,然后进行填充部件所需的每个数据集的请求。

But I seem to like the idea of once the page is loaded (or being loaded), make AJAX requests to retrieve the data needed to populate the widgets/content on the current screen. I am just concerned that the loading of page might seem clunky or slow since I am now making more requests to the server to paint the page. The initial request for the page, and then a request for each dataset needed to populate a widget.

推荐答案

我认为最好的答案是这取决于你的框架。我已经看到了解决这个问题的两种方式的网络框架。我认为,特别是当大量数据被填充到DOM,它是从性能的角度preferable装载尽可能多的网页尽可能在最初的HTTP响应,只有更新通过AJAX的需要。请注意,对于大型数据集,相比于通过JavaScript执行大量DOM操作的影响,一个额外的HTTP请求的性能开销比较小 - DOM操作可以在一些浏览器非常慢

I think the best answer is "it depends on your framework". I've seen web frameworks that handle this problem both ways. I do think that, especially when a lot of data is being populated into the DOM, it's preferable from a performance perspective to load as much of the page as possible in the initial HTTP response, and only update as needed via AJAX. Note that for large data sets, the performance overhead of an additional HTTP request is relatively small compared to the impact of performing substantial DOM manipulation via JavaScript -- DOM manipulation can be extremely slow in some browsers.

您可能会得到更详细的解答,如果你添加的框架(S)你使用。

You might get more detailed answers if you add which framework(s) you're using.

这篇关于服务器端与客户端(AJAX)正在加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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