unused-css-calculator
Calculates the percentage of unused CSS of a webpage after user interaction
Motivation
Being able to monitor the percentage of unused CSS in a page over time is useful in order to make sure this percentage says low over time.
Some other tools that provide this metric measure the amount of unused CSS right after the page loads, when a significant portion of CSS rules have not yet been applied, since the user has not interacted with the page yet.
This tool calculates the amount of unused CSS after mimicking the user interacting with the page.
For this to work you need to pass-in a callback function that describes how to simulate the user interacting with your page.
Usage
- unused-css-calculator is used along with Google's Puppeteer, a high-level API for controlling Headless Chrome.
- It requires Node.js 7.6 or greater because it relies on async\await.
- The
calc
function takes two parameters- A Puppeteer
browser
instance (the result of runningpuppeteer.launch()
- A function describing how to simulate the user interacting with the page. Should return a promise.
- A Puppeteer
const puppeteer = ;const calc = ; { const browser = await puppeteer; const unusedCSS = await ; console; await browser;};
Running tests
Run tests with npm test
License
MIT