Skip to content

Instantly share code, notes, and snippets.

@yoavweiss
Created January 15, 2026 17:38
Show Gist options
  • Select an option

  • Save yoavweiss/1c77b8d30943b6a831eb69d920961f13 to your computer and use it in GitHub Desktop.

Select an option

Save yoavweiss/1c77b8d30943b6a831eb69d920961f13 to your computer and use it in GitHub Desktop.
Extracting CSS costs from RUM
const totalStyleCost = async () => {
return new Promise(resolve => {
let total = 0;
const obs = new PerformanceObserver(entryList => {
const entries = entryList.getEntries();
for (const entry of entries) {
if (entry.paintTime) {
total += entry.paintTime - entry.styleAndLayoutStart;
} else {
total += entry.startTime + entry.duration - entry.styleAndLayoutStart;
}
for (const script of entry.scripts) {
total += script.forcedStyleAndLayoutDuration;
}
}
resolve(total);
});
obs.observe({type: "long-animation-frame", buffered: true});
});
}
const totalStyleCostSync = () => {
let total = 0;
const obs = new PerformanceObserver(() => {});
obs.observe({type: "long-animation-frame", buffered: true});
const entries = obs.takeRecords();
for (const entry of entries) {
if (entry.paintTime) {
total += entry.paintTime - entry.styleAndLayoutStart;
} else {
total += entry.startTime + entry.duration - entry.styleAndLayoutStart;
}
for (const script of entry.scripts) {
total += script.forcedStyleAndLayoutDuration;
}
}
return total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment