Tree-shaking Tailwind / Swap it out entirely, since it takes 60% of the time in a near-empty page #4802
Replies: 3 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
Some random thoughts: Even though "never ship unused CSS again" is a good objective for "normal" websites, it seems impossible with NiceGUI. The server can't know which classes will be used, e.g. by dynamically adding elements or even constructing class names on the fly. Therefore I don't see how we can ship less Tailwind without cutting functionality. And you have to distinguish between 366KB, that are loaded once, can be cached and don't need to be loaded "ever" again, and 11KB which will be - as far as I understand - created dynamically and need to be shipped on every page load. |
Beta Was this translation helpful? Give feedback.
-
Results are in! Test code: from nicegui import ui
ui.label('Hello, NiceGUI!').classes('text-2xl text-blue-500')
ui.run(tailwind=True) # Overriden False: Tailwind JIT instead of full Tailwind CDN JS Without Tailwind JIT: Scripting: 2415ms With Tailwind JIT: Scripting: 672ms So the new loading time is only 25% of original. In other words, that's 4 times faster! 🚀 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Apparently, the selling point of Tailwind CSS was that it can tree-shake and be minimal.
NiceGUI doesn't do that, and so the profiling looks like this 🤮:
(visiting
/other_page
in docs: a page with just a label)So Tailwind takes up 2260ms in a page which totals to 3855ms, contributing to 60% of the load time!
If we can make Tailwind more light and fast, then we can make NiceGUI faster as a direct result.
I know you can disable tailwind by
tailwind=False
inui.run
, but making things all ugly isn't the way to go IMO.Currently considering:
Beta Was this translation helpful? Give feedback.
All reactions