Mmm Donuts
Mmm Donuts

Reputation: 10283

What are the pros of using a javascript bundler?

I'm sorry if this question has been asked before, but I couldn't find a solid answer.

In essence, I'm building quite a large application in React that has loads of components and javascript files. The manager is pretty much pressing us to use Webpack, which I'm just starting to get my feet wet with right now.

So I suppose the question is, why go through the trouble of bundling loads and loads of already neatly separated javascript files to a few single massive files?

Upvotes: 2

Views: 555

Answers (2)

GnrlBzik
GnrlBzik

Reputation: 3358

This is more of a larger architecture related QandA it seems.

But in essence, bundling is great if

1) you have complex folder structure where each module is separate file

2) want to deliver only one file to optimize http requests and cache

3) if you utilize some sort of module export syntax.

4) With webpack you can also do hotreloading of JS and CSS with dev server, very neat.

5) also can plug in transpiler and use ES6

Upvotes: 1

Evan Trimboli
Evan Trimboli

Reputation: 30082

The main reason is it's a lot faster to load 1 single file. Let's assume you don't compress the concatenated single file at all, there's still overhead in setting up http connections, as well as maximum concurrent request limitations that prevent simultaneous downloading.

Another reason is that allows a compressor to parse an entire file. Assuming you compress each file in isolation, you could (possibly) run into naming collision issues.

You definitely want to compress your file because you'll be sending less bytes over the wire. Since you'll already need to do some post-processing of your files, compressing isn't much extra.

Upvotes: 1

Related Questions