Performance · JavaScript and CSS

Duplicated JavaScript

Two scripts on this page each bundle their own copy of the same date formatting module, so the browser downloads that code twice.

How this page is built

The page loads two minified bundles, bundle-header.js and bundle-footer.js. Each one starts with its own copy of a 60-function date formatting module, src/shared/date-format.js, and each has a source map that names it. Both bundles run every function, so the code is used, but the browser downloads it twice.

The first bundle stores its dates on this paragraph.

Why it matters

When separate bundles each include a copy of the same module, every copy has to be downloaded, parsed and compiled. The page gains nothing from the second copy. It often happens when two parts of a site are built separately, or when a bundler is set up to make one bundle per entry point without a shared chunk.

How to check it

Run Lighthouse or PageSpeed Insights on the page and look at the diagnostics. Crawl tools that run Lighthouse for each page, or that measure page resources, report the same finding across the site. Lighthouse reads each script’s source map to see which modules it contains, then lists modules found in more than one script. Without source maps it cannot see the duplication.

How to fix it

Move shared code into one shared chunk that both entry points load, using the bundler’s code splitting options. Check that two versions of the same package are not installed, and remove duplicates from the dependency tree.

Back to all tests