简体   繁体   English

使用Ajax并行页面加载

[英]Parallel page loading using ajax

Suppose I have a page which contains a four blocks. 假设我有一个包含四个块的页面。 Each block contains a lot of html code. 每个块包含很多html代码。 It take a lot of time to load whole page especially in old browsers like ie8. 加载整个页面需要很多时间,尤其是在像ie8这样的旧浏览器中。 Could I speed up page loading using ajax requests? 我可以使用ajax请求加快页面加载速度吗? I mean send ajax request to get each part of the page. 我的意思是发送ajax请求以获取页面的每个部分。 Someone tell me that ajax requests working in parallel instead of single thread page render that's why it will help to decrise page loading time. 有人告诉我,ajax请求可以并行工作,而不是单线程页面渲染,因此这将有助于减少页面加载时间。 Is it true? 是真的吗

All I/O operations on javascript runs in parallel, you only need to start all of them and wait for all to complete, promises (aka Deferreds on jQuery) was designed for that using .when . javascript上的所有I / O操作都是并行运行的,您只需要启动所有这些操作并等待所有操作完成即可, promise (即jQuery上的Deferreds)是使用.when设计的。 Example: 例:

$.when(
  $.get("/resource1"),
  $.get("/resource2"),
  $.get("/resource3")
).done(function(response1, response2, response3) {
  // do things with response1, response2 and response3;
});

more info: http://learn.jquery.com/code-organization/deferreds/jquery-deferreds/ 更多信息: http : //learn.jquery.com/code-organization/deferreds/jquery-deferreds/

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

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