Fix guides · Performance

How to fix “Legacy JavaScript”: stop shipping code for old browsers

Polyfills and transforms for browsers almost nobody uses any more. What they cost, who can fix them, and how to change your build on Shopify, WordPress, Webflow, Wix, Squarespace and Next.js.

Time to fix
15–60 minutes
Skill needed
Developer
Who notices
Every visitor: extra code to download and run

Why it matters

Older build setups rewrite modern JavaScript into a longer form and add “polyfills” so it also runs in browsers from many years ago. Every modern browser then downloads and runs that extra code for nothing.

Chrome flags a page when more than 5 KiB of this is found for features that all current browsers support.

“The vast majority of websites do not need to support older, ES5-only browsers.”

Chrome: Legacy JavaScript insight

Before you start

  • Check whose files your report lists. Only your own build can be changed. Scripts from apps, plugins and widgets are built by their developers; you can ask them to update, or replace the tool.
  • If you build your own JavaScript, the fix is a build setting: target the browsers your visitors actually use, such as “baseline widely available” in Browserslist.
  • Your analytics shows which browsers your visitors use. Check before dropping support for any.

Fix it on your platform

Shopify

  1. Flagged files are usually from apps. Remove apps you don't use, and ask the developers of the rest whether a modern build is available.
  2. If your theme has its own build step, update its Browserslist target (see “Any other site”).

WordPress

  1. Flagged files usually come from plugins or the theme (the file address shows which). Update them: newer versions often ship modern builds.
  2. Replace plugins that are no longer maintained.
  3. If you build your own theme scripts with @wordpress/scripts or another bundler, update its Browserslist target.

Webflow Managed by the platform

  1. Webflow builds its own scripts, and you can't change how.
  2. If flagged files come from your custom code or embeds, ask the provider for a modern version or remove the script.

Wix Managed by the platform

  1. Wix builds its own scripts, and you can't change how.
  2. If flagged files come from apps or custom code, remove the ones you don't need.

Squarespace Managed by the platform

  1. Squarespace builds its own scripts, and you can't change how.
  2. If flagged files come from code injection, embeds or extensions, remove the ones you don't need.

Next.js

  1. Next.js already targets modern browsers by default. If code is flagged, check for a browserslist entry in package.json or a .browserslistrc file that targets old browsers, and remove or update it.
  2. A custom Babel config (.babelrc) can also add transforms; remove it if you don't need it.
  3. Flagged third-party packages may ship pre-built old code; look for a newer version.

Any other site

  1. Set your Browserslist target to modern browsers, in package.json or .browserslistrc. Babel's preset-env, and most bundlers, read it.
  2. Rebuild and redeploy, then compare your bundle size.
package.json
"browserslist": [
  "baseline widely available"
]

Check that it's fixed

  • Re-run your StudioLNC audit: your own files should no longer be listed under Legacy JavaScript.
  • Test your site in the browsers your visitors use.

Find every issue like this on your site

Free audit of performance, accessibility, SEO and security, with fixes for your platform.