Chrome extension performance: 4 loading strategies tested
Originally published on Extenify. Chrome extension performance problems never show up in your own page speed reports, only in everyone else's. Your content script shares the main thread with every site it runs on, so a
Originally published on Extenify.
Chrome extension performance problems never show up in your own page speed reports, only in everyone else's. Your content script shares the main thread with every site it runs on, so a heavy bundle quietly slows down every tab, and users respond with a "makes Chrome laggy" one-star review. We loaded the same 1.4 MB content script four different ways and measured the difference, and the result surprised us: the default document_idle timing barely helps.
Where the cost actually comes from
An extension can cost performance in four places, but only one of them is paid on every page load:
| Part | Runs when | Hits page speed? |
|---|---|---|
| Content scripts | Every page that matches | Yes, on the page's main thread |
| Service worker | An event wakes it | No, but a worker that never sleeps holds memory |
| Popup / side panel | User opens it | No, it just feels slow |
| Storage and messaging | When you call them | Indirectly, through large reads and chatty messages |
Content scripts dominate because their cost is multiplied by every tab and every navigation. Match <all_urls> with all_frames: true and you also run inside every ad and embedded video iframe.
Four loading strategies, one heavy script
The test script was deliberately heavy: a 1.4 MB bundle (thousands of small functions, standing in for a UI library) plus an init step that reads the layout of every element and adds a badge. It ran on a 1,600-element page, 21 loads per variant, comparing medians:
| Strategy | First paint | Load event | Extra main-thread work |
|---|---|---|---|
| No extension | 88 ms | 38 ms | none |
document_start |
248 ms | 217 ms | +183 ms |
document_idle (default) |
80 ms (range 64 to 256) | 204 ms | +148 ms |
| Idle loader, heavy part after load | 76 ms | 53 ms | +56 ms |
| Idle loader, heavy part on user action | 76 ms | 64 ms | none until used |
Three things stand out:
-
document_startblocked first paint on all 21 loads. Only tiny code that must beat the page's own scripts belongs there. -
document_idlemostly moves the cost around. Chrome picks a moment betweendocument_endand just afterwindow.onload, so first paint sometimes escaped and sometimes didn't. The load event was delayed every time, and total work barely dropped. - Splitting the script is what fixed it. A small loader that waited for load plus idle time, then pulled in the heavy bundle, matched the baseline for paint and load.
Treat these as a comparison between strategies, not a benchmark for your extension. Your code, your users' hardware and the sites they visit will change the numbers.
The fix: a tiny loader plus a lazy bundle
The pattern looks roughly like this. Your manifest injects only loader.js; the heavy file is listed under web_accessible_resources:
// loader.js: decide cheaply, load expensively later
if (document.querySelector('[data-product-list]')) {
const start = () =>
requestIdleCallback(() => import(chrome.runtime.getURL('heavy.js')));
document.readyState === 'complete'
? start()
: addEventListener('load', start, { once: true });
}
If a feature only matters after a toolbar click or shortcut, skip the content script entirely and call chrome.scripting.executeScript from the click handler. With activeTab, you don't even need host permissions for that.
Other fixes worth a pass, roughly by impact:
- List specific sites in
matchesinstead of<all_urls>. Pages you don't match pay nothing. - Batch DOM reads before writes, and prefer
IntersectionObserverover callinggetBoundingClientRect()in a loop. - Narrow
MutationObservertargets and batch the handling withrequestAnimationFrame. - Leave
all_framesoff unless you truly need iframes. - Let the service worker sleep. Keep state in
chrome.storageand usechrome.alarmsfor periodic work instead of keep-alive hacks.
Measure it, then keep measuring
For a quick manual check, use a clean profile with only your extension and:
- Chrome Task Manager (Shift + Esc on Windows/Linux): watch for memory that only grows and CPU while you're idle.
-
DevTools Performance panel: record a reload, open Bottom-Up, group by URL and find your
chrome-extension://entry. - Lighthouse: if your extension spends more than 100 ms scripting, other developers auditing their sites see a "Chrome extensions negatively affected this page's load performance" warning with your extension ID in the URL.
Manual checks catch big problems once. To catch regressions on every build, the original guide includes a full Playwright script that loads a fixed test page with and without your unpacked extension, compares median main-thread work through the Chrome DevTools Protocol, and fails CI when you exceed a 50 ms budget, the same threshold DebugBear used for "minimal impact" in its scan of thousands of popular extensions.
After release, two cheap signals matter most. Time your own init with performance.now() and report aggregates, not URLs. Avoid performance.mark() in content scripts: those entries land on the host page's own performance timeline, where the site's monitoring can read them. Then watch new reviews for words like "slow", "lag" and "freezes", and line them up with your version history so a slow update is caught in days.
Key takeaways
- Content scripts run on the page's main thread, so their cost is paid on every matching page load.
-
document_startblocked first paint on every load in our test;document_idlestill added about 150 ms of work and delayed the load event. - A small loader plus a deferred or on-demand
import()removed the paint and load delay. - A Playwright check with a 50 ms budget in CI keeps the extension from getting slow again.
- Review complaints about speed usually trace back to a specific version.
The full walkthrough, including the complete Playwright test and the FAQ, is in the Chrome extension performance guide to measuring and fixing page slowdowns. If you want rating, review and version alerts across the Chrome, Edge and Firefox stores in one place, take a look at Extenify's extension review and rating monitoring.
Have you ever traced a "slow" review back to a specific content script change, and what was the culprit?
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.