Lighthouse flags every JavaScript file with more than 20 kibibytes of unused code:
See the Lighthouse performance scoring post to learn how your page's overall performance score is calculated.
The Coverage tab in Chrome DevTools can give you a line-by-line breakdown of unused code.
The Coverage
class in Puppeteer can help you automate the process of detecting unused code and extracting used code.
Check out the following Tooling.Report tests to find out if your bundler supports features that make it easier to avoid or remove unused code:
If you are using Angular CLI, include source maps in your production build to inspect your bundles.
Consider removing unused JavaScript assets and only attach the needed Drupal libraries to the relevant page or component in a page. See the Defining a library for details.
Consider reducing, or switching, the number of Joomla extensions loading unused JavaScript in your page.
Disable Magento's built-in JavaScript bundling.
If you are not server-side rendering, split your JavaScript bundles with React.lazy()
. Otherwise, code-split using a third-party library such as loadable-components.
Consider reducing, or switching, the number of WordPress plugins loading unused JavaScript in your page.
Coverage