1

我目前正在创建一个小型待办事项网站,并且我有多个与 ajax 和性能相关的问题......所以这是我的问题:

  1. 为了减少请求的数量,我想从一个请求中获取所有数据,所以我将传递例如这些属性:

    1.1。获得1个任务:

    entity=task&id=2&type=single&extra=subtasks%%contexts

    1.2. 在一个列表中获取任务和事件列表:

    entity=task%%event&user_id=2%type=multiple%order=date&limit=10

    你认为它会减少请求的数量并提高一些性能吗?

  2. 如果所有请求都转到一个文件,这意味着该 .php 文件可能很大,是不是很糟糕?还是真的不重要?

  3. 对于上市。我将能够更改列表的顺序,并可能以某种方式对其进行过滤。您认为将所有任务和事件加载到
4

1 回答 1

1

To keep things fast there are two concerns:

  1. Reduce HTTP requests – if you need two separate bits of data, send them in one file.
  2. Keep the content delivered in each AJAX request small – gzip and caching works wonders here.

So, yes, bundle things together. Large PHP file doesn't make any difference, DB queries are the only real bottleneck in a normally trafficked webpage.

For filtering and sorting, a good approach is to use JSON for the AJAX response, then sort/filter based on that on the client side if you are talking about a smallish number of items (probably upto 1000 items). If you have 100s of thousands of items, then returning a subset from the server will be better.

于 2011-10-09T19:32:57.697 回答