更好的许多小Ajax请求,或一个大的全球网站的性能? [英] better many small ajax request or a big one for global site performance?

查看:167
本文介绍了更好的许多小Ajax请求,或一个大的全球网站的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个词preSS站点返回帖子列表,只有标题,网址,日期和类别中的AJAX搜索字段。

I have a wordpress site with an ajax search field that returns a list of posts, with just the title, the url, the date and the category.

我想分页结果让最多10个结果显示每一次。

I want to paginate the results so that max 10 results are shown every time.

我的疑问是:它的好处是,使不同的请求动辄页面被打开或使只有一个请求,以获取所有的职位,然后通过javascript管理分页(的反应是我的JSON)

My doubt is: is it good to make a different request every turn the page is turned or make only one request to fetch all the posts and then manage the pagination via javascript (the response is i JSON)?

它是更好地与光响应或一个大的更加频繁地小的要求?

Is it better to make more frequent small request with a light response or a big one?

我想,在工地生活的开始,第一个解决方案是最好的。我不知道有关的可伸缩性随着网站的发展。

I suppose that at the beginning of the site life the first solution is the best one. I'm not sure about scalability as the site grows.

你怎么看?

更新:我收到了几个很好的答案,有解决更多的问题的用户界面侧

UPDATE: I received a couple of very good answer, there were addressing more the user interface side of the problem.

HWR我希望你能更专注于性能的角度来看。我的网站是一个共享的服务器上,但我们预计流量上去快,因为该网站将得到国际曝光。 我担心的是这个词preSS将无法应付增加的开销来自Ajax请求。

Hwr I would like you to focus more on the performance point of view. My site is on a shared server but we expect traffic to go up fast, since the site will receive international exposure. My fear is that wordpress will not be able to cope with the increased overhead that comes from the ajax requests.

所以回到这个问题,会是什么服务器总负荷比较好,很多小的请求,只加载请求的结果页面或一个大的所有的结果?

So going back to the question, what would it better for the server total load, many small requests, loading only the requested result page or a big one with all the results?

考虑到并不是所有的用户我想,要检查所有的结果页面我想第一个...

Considering that not all the user i suppose are going to check all of the results pages i suppose the first...

推荐答案

正确的答案是:这取决于

The correct answer is: "It depends".

如果你处理已知量(10个结果每页10页的结果),你希望他们都可以提供给用户,尽快,那么我建议下载块(10或20)在500毫秒计时器或类似的东西。

If you were dealing with known quantities (10 results per page, 10 pages of results), and you wanted all of them to be made available to the user, asap, then I'd suggest downloading chunks (10 or 20) on a 500ms timer or something similar.

然后就可以填补多余的背页异步,并更新了总 - 页面控件相应。

Then you can fill up the extra back-pages asynchronously, and update the "total-pages" controls accordingly.

从那里,你的用户有立竿见影的效果,并且具有来回翻转所有数据之间的2杂交秒的能力。

From there, your user has immediate results, and has the ability to flip back and forth between all of your data in 2-ish seconds.

如果你有,你需要的所有数据的访问马上一个网站,你有40的结果,需要加以显示,然后去一个大垃圾场。

If you had a site where you needed all of your data accessible right away, and you had 40 results that needed to be shown, then go with a big dump.

如果你有无限滚动的网站,那么你会想抓住一对夫妇的页面长度。对于一些像Twitter,我可能pre-计算集装箱的平均高度,相对于屏幕的高度。然后我会下载3或4的屏幕长度价值的鸣叫。 从那里,当用户被滚动到其第二或第三屏幕(或分别第三或第四),身份证下载下一个批次。

If you had an infinite-scroll site, then you'd want to grab a couple of page-lengths. For something like Twitter, I'd probably pre-calculate the average height of the container, versus the screen height. Then I'd download 3 or 4 screen-lengths worth of tweets. From there, when the user was scrolling into their 2nd or 3rd screen (or 3rd or 4th respectively), I'd download the next batch.

所以,我的事件可能被附加到一个onscroll,而如果它允许运行(如果它一直在自上一次它的运行至少16毫秒, - 显然,我们还在滚动)检查,那么它会检查的地方这是在是多么接近底部,考虑到屏幕的高度来看,和最后一批( screen_bottom&GT的总高度= latest_batch.height * 0.75 )或类似的。所述screen_bottom将是相对于所述last_batch,在于如果用户滚动备份,比previous批次更高,screen_bottom将是一个负数,完全

So my event might be attached to an onscroll, which checks if it's allowed to run (if it's been at least 16ms since the last time it's run, -- obviously, we're still scrolling), then it will check where it is, in terms of how close it is to the bottom, considering screen-height, and the total height of the last batch (screen_bottom >= latest_batch.height * 0.75) or similar. The screen_bottom would be relative to the last_batch, in that if the user was scrolling back up, higher than the previous batch, screen_bottom would be a negative number, completely.

...或归他们,所以,你只是处理的百分比。

...or normalize them, so that you're just dealing with percentages.

这是足以令它觉得数据是随时为您服务。 你不希望有等待一个巨大的块装载在开始,但你不希望等待微小块加载,你试图同时走动,无论是。

It's enough to make it feel like the data is always there for you. You don't want to have to wait for a huge block to load at the start, but you don't want to wait for tiny blocks to load, while you're trying to move around, either.

所以,搞清楚什么是幸福的介质,根据你在做什么,以及你如何期望用户来使用你的数据。

So figure out what the happy medium is, based on what you're doing, and how you expect the user to use your data.

这篇关于更好的许多小Ajax请求,或一个大的全球网站的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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