I've been hearing a lot about script loaders such as RequireJS. What's the advantage of using a script loader over concatenating your source files in a build process?
Concatenating your source files in the build process has the advantage that you the client has to make fewer requests and the request overhead is reduced and page load time decreases making it faster
eg. suppose you have 10 javascript files now the browser has to make 10 HTTP
requests and each request has its own overhead(request and response headers) now if you concatenate those 10 files to 2 or 3 there are just 2 or 3 HTTP
requests thus reducing the overhead. also any client which follows HTTP 1.1
specification does not allow more than 2 simultaneous connections to a single domain so you see why its important to have less connections(requests)
whereas script loaders are used to load javascript on-demand,it means that suppose you are only going to need some javascript if the user types in a particular text box then you dont request that javascript on page load but only load it when it is in demand(user types in the text box). eg when you tag photos on facebook the javascipt needed for tagging is not available when the photos page loads but its requested when you try to tag the photos
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With