NeovaNền tảng SEO chuyên sâu

File JavaScript vượt ngưỡng code không dùng của Lighthouse

Trong Neova Chạy khi bật Lighthouse, một thiết lập: nó dùng Chrome trên Mac của bạn.

Quy tắc được rà soát lần cuối ngày 17 tháng 10 năm 2026 · Hướng dẫn cập nhật ngày 21 tháng 9 năm 2026

Một file script chứa code mà trang không chạy trong lúc tải, nên khách truy cập tải và phân tích nó một cách vô ích. Đây là ngưỡng của Lighthouse. Không công cụ tìm kiếm nào đặt ngưỡng này.

Bạn có thể làm gì

Tách bundle để code chỉ tải khi cần, xóa code thừa, và bỏ các script bên thứ ba mà trang không dùng.

Neova tìm ra bằng cách nào

Neova chạy kiểm tra tốc độ trên một mẫu của từng loại trang.

Vì sao Neova đánh dấu

  • Khách truy cập tải và phân tích code mà trang không bao giờ chạy khi tải, tốn băng thông và thời gian của main thread.
  • Nguyên nhân thường là bundle lớn và script bên thứ ba không dùng đến.
  • Đây là mốc của Lighthouse; không công cụ tìm kiếm nào đặt nó.

Nguồn

Ticket nó tạo ra

Phần này tạm thời còn bằng tiếng Anh.

PE-024 · JavaScript File Is Over the Lighthouse Line for Unused Code

How to Check the Fix: 1. Run the check again in Neova
2. Spot-check sample URLs across affected templates
3. Record the re-check date and period label next to the baseline

Neova writes this ticket for every affected page group and sends it to Jira, Linear, Asana and the rest, after you approve it.

Hướng dẫn đầy đủ

Phần này tạm thời còn bằng tiếng Anh.

TL;DR, This audit fires when your bundles contain code the page downloads but never executes on load. Dead JavaScript still gets fetched, parsed, and compiled, so it steals network bandwidth and boot-up CPU before a single line of it ever runs, if it runs at all.

What This Check Flags

Lighthouse measures byte-level coverage of every script and reports how much of each file went unused during page load. A 400 KB bundle where only 120 KB executes has 280 KB of pure overhead: bytes the browser fetched, parsed into an AST, and handed to the compiler for nothing. This is a shipping problem, not a runtime one, the fix is to stop sending the code, not to make it run faster.

A Real Example, and the Fix

You import a whole utility library to use one function:

import _ from 'lodash';                 // pulls the entire library into the bundle
const unique = _.uniq(ids);

Even with tree-shaking configured, a default CommonJS import of lodash often drags in the full module because the bundler can't prove the rest is side-effect-free. Import the single function from its own path so only that code lands in the bundle:

import uniq from 'lodash-es/uniq';      // one function, tree-shakeable
const unique = uniq(ids);

For code tied to a screen the user may never open, don't import it statically at all, load it on demand:

button.addEventListener('click', async () => {
  const { openEditor } = await import('./editor.js'); // fetched only on click
  openEditor();
});

The Three Ways Dead Code Gets In

Unused JavaScript almost always traces back to one of these root causes. Naming which one you have points straight at the fix.

Root Cause What It Looks Like The Fix Tool
Whole-library imports import _ from 'lodash' for one helper Import single functions; use ES-module builds Tree-shaking / bundle analyzer
Everything in one bundle Route B's code shipped on Route A Route-based code splitting Dynamic import()
Polyfills for modern browsers Legacy shims served to Chrome/Safari Serve modern JS with module/nomodule Differential serving
Abandoned features Old A/B tests, dead components Delete the source; verify with coverage DevTools Coverage tab

How to Detect It

  1. Lighthouse / PageSpeed Insights: open "Reduce unused JavaScript" under Diagnostics. It lists each script with the wasted bytes and estimated savings, ranked so you fix the biggest offender first.
  2. DevTools Coverage tab: open DevTools, run "Show Coverage" from the command menu, reload, and read the unused percentage per file. Then exercise real interactions, the number should drop as code you actually use finally executes; whatever stays red on a full journey is a deletion candidate.
  3. Bundle analyzer: run webpack-bundle-analyzer or the Vite/Rollup visualizer to see which modules bloat each chunk, so you catch a fat dependency at build time instead of on a live page.

How to Fix It

  1. Turn on tree-shaking properly. Use ES-module imports, mark packages side-effect-free where safe, and build for production so the bundler can drop unreachable exports. Start with the tree shaking primer if the concept is new.
  2. Code-split by route and interaction. Load a view's code only when the user visits it. The code splitting pattern with dynamic import() is the workhorse here.
  3. Import narrowly. Pull single functions from their own paths instead of whole libraries, and prefer smaller dependencies for one-off needs.
  4. Kill dead features. Delete abandoned components and stale experiment code at the source, then re-run Coverage to confirm the bytes are gone.
  5. Defer third parties. Tag managers and widgets are often the biggest chunk of unused JS on load, audit each and load non-essential ones after first paint.

How This Differs From Reduce JavaScript Execution Time

These two are cause and effect, not duplicates. Unused JS is measured in bytes and coverage, how much code you shipped that never ran. Reduce JavaScript execution time is measured in CPU seconds, how long the code that does run takes on the main thread. Deleting unused code helps both audits, because bytes you never send are never parsed or compiled. But you can pass this audit and still fail execution time if the code you do ship runs expensively. Also note the sibling audit Minify JavaScript shrinks the code you keep; removing unused code deletes the code you don't. Do both.

FAQ

Is Unused JavaScript the Same as Unminified JavaScript?

No. Minification compresses the code you keep by stripping whitespace and shortening names. Removing unused code deletes code you never run. They stack: purge the dead code, then minify what survives.

Why Does Tree-Shaking Sometimes Fail to Remove Code?

Tree-shaking relies on static analysis of ES modules. CommonJS imports, dynamic property access, and packages not marked side-effect-free defeat it, so the bundler keeps the code to be safe. Use ES-module builds and a proper sideEffects field to unblock it.

Will Code Splitting Increase the Number of Requests?

Yes, slightly, but over HTTP/2 that trade is almost always a win, because you defer bytes the user may never need instead of blocking the first load with all of them.

How Much Unused JS Is Acceptable?

There is no hard pass line like other audits, but treat anything above roughly 40 KB of wasted script as worth chasing. On mobile, every 100 KB of unnecessary JavaScript is real parse-and-compile time on a slow CPU.

Can I Remove Unused Code From Third-Party Scripts?

Usually not directly, you don't control their bundles. What you can control is whether they load at all and when. Audit each vendor, drop the ones you don't need, and defer the rest past first paint.

Tìm lỗi này trên trang của bạn

Neova chạy mục kiểm tra này và mọi mục khác trong mỗi lần crawl, rồi viết cách sửa thành ticket cho nhóm của bạn.

  • Ứng dụng máy tính cho Mac, Windows và Linux
  • Tất cả 696 mục kiểm tra, mỗi mục kèm nguồn
  • Search Console và Analytics 4, kết nối chỉ đọc
  • Ticket sang Jira, Linear và Asana

Tải Neova Gói Desktop Free, hoặc dùng thử Solo miễn phí 14 ngày, không cần thẻ.

Tất cả mục kiểm tra Hiệu năng · Hướng dẫn · Thư viện mục kiểm tra

Do Neova Labs biên soạn · Quay lại Thư viện mục kiểm tra