CSS and JS Coverage Analyzer
Load the JSON from the Coverage panel, see how many bytes of each stylesheet and script went unused, merge exports from several pages and pull out the CSS that was used.
Berjalan dalam pelayar anda. Fail anda tidak pernah meninggalkan peranti. Lihat cara menyemaknya
…
Cara melakukannya
- 1Record coverage
Use the DevTools Coverage panel with reload on a key page and export JSON.
- 2Repeat for templates
Export coverage for each important page type as well.
- 3Open the files
Drop all exports on the page; they are merged by file.
- 4Sort the waste
Read the file table from the largest unused size down and hide extension files.
- 5Inspect code
Open a file in the code view and read the list of unused selectors.
- 6Plan and export
Pick a plan for each file, copy the used CSS and export the CSV.
Tentang alat ini
Many sites ship one large stylesheet and one large bundle to every page, and most of each file is never used on any single page. The Coverage panel in Chrome DevTools records which byte ranges of every CSS and JavaScript file actually ran or matched while you used the page, and it can export that as JSON. The panel itself shows a percentage, but it is awkward to compare files, combine several pages or get the used code out. This analyzer opens one or more of those exports. It merges overlapping ranges, decides whether each entry is CSS or JavaScript, and reports total, used and unused bytes per file, sorted by waste. When you open several exports, for example from the home page, a product page and the checkout, the same file is merged across them so a byte counts as used if any page used it. That is the honest number to act on, because code unused on one page is often needed on another. The code view shows each file with used code in green and unused in red, and for stylesheets it lists the top-level rules that never matched.
Planning the work
Each file row has a plan menu: split by page or route, defer or lazy load, purge unused rules, remove the file, or keep it. Decisions are kept with undo and included in the CSV, which makes the export a short work list for a sprint. Files you do not control, such as browser extension scripts that appear in the export, can be hidden.
Used CSS
The Used CSS tab concatenates the used ranges of every stylesheet, with a comment naming the source file. It is a starting point for critical CSS or for a trimmed stylesheet, not a finished file: hover, focus and media query states only count as used if they happened during the recording, and the order of rules matters for the cascade.
Recording well
Record with the cache disabled, then scroll the page, open menus and dialogs, switch tabs and resize the window so responsive rules apply. Then export. Repeat for each important template and open all the exports together.
Limits
Unused does not mean unneeded. Code for errors, rare states, other pages and other screen sizes will show as unused unless you exercised it. Do not delete code on this report alone; test after every change. Byte counts are characters of the file text as DevTools recorded them, before compression, so transfer savings are smaller. Raw V8 coverage files without ranges are only roughly supported.
Contoh berselesaian
A shop records coverage on its home page and its checkout and opens both exports. site.css is 182 KB, and after merging 31 KB is used on at least one of the two pages, so 151 KB (83 percent) is unused. app.js is 410 KB with 166 KB used, leaving 244 KB unused. The code view of site.css lists unused rules such as .modal, .carousel and .carousel__dot, which belong to the product page that was not recorded. The team records a product page as well, opens the third export, and the used share of site.css rises to 24 percent; they plan to purge the rest and split the checkout script into its own bundle.
Ringkasnya
- Kategori: Pembangun & data
- Berjalan dalam pelayar, tanpa pendaftaran, tanpa muat naik.
- Maklumat yang anda masukkan kekal pada peranti anda.
- Tersedia dalam bahasa Inggeris.
- Kandungan disemak kali terakhir:
- Sumber rasmi: Chrome DevTools: find unused JavaScript and CSS with the Coverage panel
Soalan lazim
How do I export coverage?
Open DevTools, press Ctrl+Shift+P or Cmd+Shift+P, run Show Coverage, press the reload button in the panel, use the page, then press the export button to save a JSON file.
Why merge several exports?
One page uses only part of a shared file. Merging pages shows the code no page needed, which is the code you can safely look at removing.
Is the used CSS ready for production?
It is a starting point. Check states you did not trigger, such as hover, focus, error messages and other breakpoints, and keep the rule order.
Why do some files show as JavaScript wrongly?
Inline scripts and styles are listed under the page URL. The tool guesses the type from the URL and contents; most entries are detected correctly.
Does it read Puppeteer or Playwright coverage?
Yes, if the export has url, text and ranges for each file, which is the format both tools produce for CSS and JS coverage.
Is anything uploaded?
No. Files are read in this tab. Only your plan choices and hidden files are kept in local storage.
