# Bundling at scale: How Javascript bundling works at Facebook

- Speaker: [Noam Elboim](/wiki/speakers/noam-elboim.md)
- Event: [Reversim Summit 2019](/wiki/years/2019.md)
- Video: https://www.youtube.com/watch?v=OvHsP5bUmMY
- Transcript: [/transcripts/2019/44-OvHsP5bUmMY.md](/transcripts/2019/44-OvHsP5bUmMY.md)
- Language: Hebrew and English · Type: talk · Level: advanced
- Topics: [Frontend](/wiki/topics/frontend.md), [Performance](/wiki/topics/performance.md), [Scalability](/wiki/topics/scalability.md), [Developer Experience](/wiki/topics/developer-experience.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

This talk explores how large-scale JavaScript bundling and code splitting are handled at Facebook to optimize browser performance. The speaker discusses the limitations of both extreme bundling approaches and manual code splitting configurations in large engineering teams. The presentation introduces an automated offline packaging algorithm that leverages multidimensional data such as display states, page phases, and user interaction frequencies. Ultimately, the audience learns how to design smarter, data-driven static resource loading strategies that improve page load times and user engagement without burdening product engineers.

## Key points

- [1:34](https://www.youtube.com/watch?v=OvHsP5bUmMY&t=94s) The primary bottleneck in modern web applications is the time it takes to download large JavaScript bundles, which directly impacts user engagement.
- [4:00](https://www.youtube.com/watch?v=OvHsP5bUmMY&t=240s) Bundling everything into a single massive file maximizes network efficiency and Gzip compression, but lacks flexibility for large-scale applications.
- [7:30](https://www.youtube.com/watch?v=OvHsP5bUmMY&t=450s) Manual code splitting becomes unsustainable and prone to code duplication as development teams and entry points scale up.
- [12:56](https://www.youtube.com/watch?v=OvHsP5bUmMY&t=776s) Facebook addresses bundling challenges through a custom offline greedy packaging algorithm that generates static resource mappings.
- [16:02](https://www.youtube.com/watch?v=OvHsP5bUmMY&t=962s) The packaging algorithm relies on multiple dimensions including page types, phases, display states, and update frequencies.
- [37:09](https://www.youtube.com/watch?v=OvHsP5bUmMY&t=2229s) Early flushing strategies allow critical high-frequency JavaScript assets to be downloaded much earlier during server-side rendering phases.
- [45:00](https://www.youtube.com/watch?v=OvHsP5bUmMY&t=2700s) Developers can improve their applications by separating display logic from non-display logic and implementing early resource flushing.

## Takeaways

- Separate critical display code from non-display or asynchronous code into distinct bundles to improve initial load times.
- Utilize data-driven metrics like code modification frequency and user interaction patterns to optimize bundle splitting.
- Implement early resource flushing techniques to download high-probability JavaScript assets while the server is rendering.

## Questions this talk answers

- How can you automate code splitting in a large application without relying on manual configuration?
- What metrics should be used to determine whether a JavaScript module belongs in an initial bundle or a deferred bundle?
- How does separating display and non-display logic impact the time-to-interactive metric?

## Technologies

JavaScript, React, Webpack, Rollup, Parcel

## Tags

bundling, code splitting, frontend infrastructure, performance optimization, scalability
