Best way to minify JavaScript files in Chrome Extension Manifest V3

519 views
Skip to first unread message

Adnan Khan

unread,
Apr 11, 2024, 6:05:09 PM4/11/24
to Chromium Extensions
I searched this question alot but rarely got any answer.

I do see some perfect chrome extensions with every inch of Content Script completely minified and unreadable which we want to achieve.

Here it thing thing,

We have good amounts of Content Script files perfectly organized, many of files are dependent on each other so we can not minify anything right now because it breaks one or the other.

Please suggest more professional and modern approach toward minification process for Content Scripts that are written in Classes concepts and have dependent helperfunction files.

Patrick Kettner

unread,
Apr 11, 2024, 6:33:37 PM4/11/24
to Adnan Khan, Chromium Extensions
Hello Adnan!
Using a build tool like rollup, parcel, or webpack will be what you are looking for. They can create a dependency graph, where the minification of a value is reflected throughout the entire generated output of the project.

patrick

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/7a583055-5ece-4181-8e52-7832579fb21dn%40chromium.org.

Adnan Khan

unread,
Apr 11, 2024, 6:49:58 PM4/11/24
to Chromium Extensions, Patrick Kettner, Chromium Extensions, Adnan Khan
Thanks Patrick for answer.

Actually I've tried Rollup and currently using it too but the minification only works well for service-worker file. For rest of content scripts, that has dependencies, like for instance one function from helperFuncs.js that is called in other content scripts is not correctly minified. 
What's the solution for such thing?

wOxxOm

unread,
Apr 12, 2024, 7:35:08 AM4/12/24
to Chromium Extensions, Adnan Khan, Patrick Kettner, Chromium Extensions
Instead of listing multiple content scripts in "js" key, use a single file that imports stuff from other files, so that the output will be a single file too.

Adnan Khan

unread,
Apr 12, 2024, 7:37:57 AM4/12/24
to Chromium Extensions, wOxxOm, Adnan Khan, Patrick Kettner, Chromium Extensions
A nice idea but would that work? as currently, we execute content script on specific sites, it means we would have to just use one generic content script on all sites right?

wOxxOm

unread,
Apr 12, 2024, 7:41:28 AM4/12/24
to Chromium Extensions, Adnan Khan, wOxxOm, Patrick Kettner, Chromium Extensions
You can generate several different bundles. It might waste some disk space but unless you have dozens of huge files it should be fine. I'd also argue that content scripts shouldn't be big by default and instead should load code on demand using chrome.scripting.executeScript in the background script or dynamically importing from web_accessible_resource.
Reply all
Reply to author
Forward
0 new messages