Suppose I have a page which contains a four blocks. Each block contains a lot of html code. It take a lot of time to load whole page especially in old browsers like ie8. Could I speed up page loading using ajax requests? I mean send ajax request to get each part of the page. 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. Is it true?
Asked
Active
Viewed 362 times
1
-
Not sure but don't think it works like that, since ajax loads after DOM loads then it makes another trip to request more stuff.. maybe some kind of ajax lazy loading will work – vico Sep 15 '14 at 15:25
-
It will probably be slower. IE8's rendering engine, especially on large html that requires re-painting (ie, expanding width tables) is very slow. If you can, try to set hard pixel widths on your blocks/cells, as it will improve ie8's painting ability. – BReal14 Sep 15 '14 at 15:26
-
You can also use but there's no support for ie8 & 9. http://stackoverflow.com/questions/30036/javascript-and-threads – Daniele Vrut Sep 15 '14 at 15:33
-
@vico I could start AJAX requests before DOM loading, is not? – Neir0 Sep 15 '14 at 15:41
-
your page would need to wait for server response, load data, then repeat the process 4 more times at once. You can setup a demo to test this easily and then just look at the network log to see if time improves or not compared to normal load. ( delay for response can be 500ms to 2.5s depending on server and what it is processing ) – vico Sep 15 '14 at 15:56
1 Answers
0
All I/O operations on javascript runs in parallel, you only need to start all of them and wait for all to complete, promises (a.k.a. Deferreds on jQuery) was designed for that using .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/

dseminara
- 11,665
- 2
- 20
- 22
-
-
If you are working with ajax, and the page load involves using ajax requests, then is recommended to make the ajax request that way to reduce wait time But using ajax requests itself instead of letting the browser do the job doesn't improve the page load time, in fact, I suggest to let the browser do the job where/when possible – dseminara Sep 15 '14 at 15:42