Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Javascript : HTTP Requests -v- Asynchronous Loading

I'm having difficulty in deciding which approach is better in terms of site performance.

Either to have all required jQuery plugins in one file to be included on every page on the site OR split the plugins out to individual files and use the jQuery.getScript() method to load them as and when required.

Is there any real benefit in loading the scripts asynchronously over one http request?

All my Javascript will be minified and gzipped.

Thanks!

like image 248
jigglyT101 Avatar asked Dec 20 '10 01:12

jigglyT101


People also ask

What is asynchronous JavaScript loading?

Synchronously, where scripts are loaded sequentially, one after another, starting with the <head> tag. Asynchronously, where some scripts can be loaded simultaneously.

Is HTTP request synchronous or asynchronous?

XMLHttpRequest supports both synchronous and asynchronous communications. In general, however, asynchronous requests should be preferred to synchronous requests for performance reasons. Synchronous requests block the execution of code which causes "freezing" on the screen and an unresponsive user experience.

Does JavaScript run synchronous or asynchronous?

JavaScript is a single-threaded, non-blocking, asynchronous, concurrent programming language with lots of flexibility.

Is HTTP request asynchronous?

The HTTP asynchronous request-response behavior is asynchronous only because IBM® App Connect Enterprise treats the request and the response as such, enabling the message flow to retrieve the next message without waiting for the response from the asynchronous request.


2 Answers

From my poit of view the best solution until now is controljs

Read the complete post http://www.stevesouders.com/blog/2010/12/15/controljs-part-1/

like image 44
Martin Borthiry Avatar answered Oct 10 '22 13:10

Martin Borthiry


It's not so simple and depends on the distribution of javascript across your site. Have a look at this question : Which is better for JavaScript load-time: Compress all in one big file or load all asynchronously?

like image 132
David Tang Avatar answered Oct 10 '22 13:10

David Tang