brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the Coverage panel shows how much of your CSS and scripts a page never uses

Web-Development
~/tips/tip-coverage-panel-unused-code

choose "Per function" or "Per block" > click the reload button in the panel

Find the stylesheets and scripts that mostly ship dead weight to a page.

Sites tend to load one big stylesheet and a bundle of scripts on every page, whether the page needs them or not. Chrome’s Coverage panel measures how many bytes of each file were actually used.

Ctrl+Shift+P (Cmd+Shift+P on a Mac) > type "coverage" > Show Coverage
choose "Per function" or "Per block" > click the reload button in the panel

The panel opens in the drawer at the bottom of DevTools. After the reload it lists each CSS and JavaScript file with its total size, the unused bytes and a bar that shows used versus unused. Keep using the page while it records, because opening menus and dialogs runs code that the first load did not.

Click a file and it opens in the Sources panel with a colored marker in the gutter for each line: used code and unused code get different colors. That is where I’d expect leftovers, like styles for a component the site no longer has.

Per block also marks unused parts inside a function, while per function only tells you whether a whole function ran.

Read the numbers with care. Unused means unused during this recording on this page, not unused anywhere. A rule for the checkout page shows as dead weight on the homepage, and code for an error state only runs when something fails. Use the panel to find candidates for splitting files per page, and do not delete code just because one page has no use for it.

Further reading: Chrome DevTools: Coverage

More Web-Development tips ab -n 200 -c 10 https://example.com/ console.assert(items.length > 0, 'cart is empty', items) document.designMode = "on" function save(item) { Save draft All Web-Development tips (67) All topics

Link