Finding and ranking your worst Java Script offenders
Most JavaScript performance issues aren't distributed evenly. A handful of large dependencies or inefficient third-party scripts account for most problems, and identifying those worst offenders reduces main-thread blocking, improves INP, and accelerates LCP and FCP. Use these three ranking methods to find the 20 percent of JavaScript causing 80 percent of your performance problems, then prioritize removing or optimizing those files.
Anchor to Rank by bytes: Lighthouse TreemapRank by bytes: Lighthouse Treemap
The Treemap visualizes JavaScript files and modules as boxes sized by bytes so that you can quickly identify the largest dependencies.
Steps:
- Run a Lighthouse test.
- Open the Treemap link from the report.
- Identify the largest boxes.
- Drill into modules if source maps are available.
Look for unused third-party scripts, large dependencies with smaller alternatives, scripts from services that are no longer used, and duplicated functionality.
Anchor to Rank by scripting time: Chrome DevToolsRank by scripting time: Chrome Dev Tools
Chrome DevTools measures the total time spent executing JavaScript during page load.
Steps:
- Open Chrome DevTools and select the Performance tab.
- Record a page load.
- Check the Bottom-Up or Call Tree view.
- Sort by Self Time or Total Time.
- Filter by domain using search.
Blocking time affects the user experience most directly. It prevents the browser from responding to user input.
Steps:
- Run WebPageTest.
- Navigate to the Processing Breakdown view.
- See the Main Thread section.
- Review the scripts ranked by total blocking time.
You can also block specific domains to measure their impact.
Anchor to Theme CheckTheme Check
Shopify's linter identifies performance issues in theme code.
Theme Check catches:
- Remote assets from external domains.
- Parser-blocking scripts, through the
ParserBlockingScriptcheck. imgtags missingwidthandheightattributes, through theImgWidthAndHeightcheck.
The AssetSizeCSS and AssetSizeJavaScript checks also flag oversized bundles, at a default of 100000 raw bytes for CSS and 10000 raw bytes for JavaScript. Both measure the raw file size, not the minified or compressed size, and neither runs until you enable it in .theme-check.yml. See Theme Check linting tool for the configuration.
To run Theme Check, use Shopify CLI: shopify theme check.
Anchor to Recommended workflowRecommended workflow
Use these tools in sequence to systematically reduce JavaScript overhead:
- Run Theme Check during development.
- Fix the issues it identifies.
- Use Lighthouse Treemap for final bundle analysis.
- Use WebPageTest for real-world impact testing.
- Verify that all scripts are still needed.
- Remove scripts from unused services.
- Remove legacy or duplicate scripts.
- Evaluate with marketing and stakeholders whether the performance cost is worth the feature benefit.
- Look for smaller, more performant alternatives for large dependencies.
Anchor to ReferencesReferences
- 3 ways to find your worst JavaScript offenders for page load
- Theme Check configuration
- Audit and remove third-party scripts
- Theme Check linting tool
- Understanding INP