Created
January 15, 2026 17:38
-
-
Save yoavweiss/1c77b8d30943b6a831eb69d920961f13 to your computer and use it in GitHub Desktop.
Extracting CSS costs from RUM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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