Uglyfy and a brython_bare.js ?

Skip to first unread message

Denis Migdal

Oct 4, 2023, 2:59:00 PM10/4/23
to brython

I was wondering if anyone tried to uglify brython.min.js (it rewrites the name of some local variables to shorter ones). If so, did it work or did it explodes ? Was the gain significant ?

Also, brython.min.js is quite big (almost 1MB). Do you know if it is possible to build one without some builtin modules ?

TBF I'd find quite interesting to have a "brython_bare.js" (for dev and to see the size), that'd include 0 modules, only the bare minimum to execute Python code, downloading missing modules when needed (just like when brython_sdlib.js is missing). Then could have a tool like the one for brython_stdlib.js to build our own "brython.js" tailored to our specific needs.

Having smaller files means quicker initial page load (which could be significant on smartphones), therefore better SEO scores (which could be a constraint for some devs).


Pierre Quentel

Oct 6, 2023, 4:36:07 PM10/6/23
to brython
Hi Denis,

brython.min.js is already the minification of brython.js by [terser](, it replaces uglify.js which doesn't support ES6+.

A few kB might be saved if you removed the content of builtin_modules.js (Brython-specific modules browser, browser.html, javascript + modules _sys and _warnings used internally), it would not make a big change overall; having them in brython.js avoids loading the stdlib (currently 4.5MB) for scripts with only basic interaction with the DOM.

As you mention, a specific command (brython-cli make_modules) generates a file brython_modules.js that groups all the scripts (user-defined + in stdlib) liable to be imported by a specific application. More details in the documentation, section "Optimization".

Denis Migdal

Oct 6, 2023, 5:10:34 PM10/6/23
to brython
Thanks for your answer.

This is quite a shame that brython.js is so big. Fortunately it seems that, once compressed, it goes from 1MB to 200kB.

On another subject, did you received the private message I sent through the Google Groups ? (not sure if it was sent).
Reply all
Reply to author
0 new messages