Faster, smaller bundles using Bundle Buddy and webpack’s CommonsChunkPlugin

Vivek Nayyar
Nov 1, 2017 · 3 min read

It’s not an everyday thing that you come across an amazing plugin which helps in reducing all your bundle sizes by a great extent and improves your web performance.

A normal day in office and I installed bundle buddy an amazing plugin by Sam Saccone.

For those not aware of Bundle Buddy, it is described on it’s README as:

Bundle Buddy is a tool to help you find source code duplication across your JavaScript chunks [aka Bundles].

Measure and Diagnosis

After installing bundle buddy, I ran it for the first time and to my surprise my entire codebase had 1351 files bundled into 16 bundles and of those 14 bundles had overlap.

Below is how Bundle Buddy visualizes this for you:

The areas highlighted with red border show that 14 bundles in total have overlap and one of the chunk by the name watch-page has 73% code which is shared with 13 other bundles.

Since I wasn’t very sure about how to resolve this, I did what any developer would do, which is to ask for help on twitter and that’s where I received the solution for this problem from Sean T. Larkin and Sam Saccone.

And that’s exactly what I did and the results were amazing. The bundle buddy results after using CommonsChunkPlugin and async are clearly depicted in this UI:

Optimize and Asses

As we see all the overlap’s that we had in our code disappeared and now we have just one common chunk which has all the code which was previously being shared across multiple modules.

The highlighted portion in red depict that after using CommonsChunkPlugin only 8 bundles have overlap and my watch-page chunk which previously had 73% code being shared with 13 other modules now just has 26% code being shared with just 1 other module which is a big achievement.

Here is how we configure the CommonsChunkPlugin:

This reduces the size of our asynchronous bundles by removing common code across them, and extracting them into a shared “common” async bundle.

The trade-off of CommonsChunkPlugin in this case is that it removes duplicate code at the cost of creating an extra network request when requesting a asnyc bundle.

Is the tradeoff worth it?

Yes! The only time that network requests become a bottleneck is when (for HTTP/1) you exceed 5–6 parallel requests (typically seen during initial page load). In most cases, lazy loaded bundles are fetched after all other resources have downloaded for your initial page! So at most we may only have 2–3 parallel requests!


For further reading about Bundle buddy and webpack-bundle-buddy, please refer to the following links:-

A big thanks to Sam Saccone and Sean T. Larkin for helping me in this, you guys are amazing.

I have immense respect for the both of you and everyone else who is actively maintaining there OSS projects and helping newbies like me.


Use bundle buddy with CommonsChunkPlugin. They work so well together and help us in making our bundles smaller, give us better caching and an improved web performance.

I will be posting more articles related to Web Performance and other plugins that help us with best practices. If you wish to be updated with my latest posts, please find me on Twitter — @viveknayyar09.

Thank you Vivek Nayyar for this community contribution to the webpack open source project!! If you have a great post about webpack and want it featured on our publication, feel free and email our team at or DM Sean T. Larkin (TheLarkInn) on twitter!

No time to help contribute? Want to give back in other ways? Become a Backer or Sponsor to webpack by donating to our open collective. Open Collective not only helps support the Core Team, but also supports contributors who have spent significant time improving our organization on their free time! ❤


The official Medium publication for the webpack open source…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store