Menu

13.3 per cent of our HTML is class attributes, 324 distinct strings doing it, and the proof tailwind-merge works is a class that is missing
📰

13.3 per cent of our HTML is class attributes, 324 distinct strings doing it, and the proof tailwind-merge works is a class that is missing

DEV Community: css·Daniel Pertu·16 days ago
#XKA9x0wO
#devtocss#devto#dev#class#rounded
Reading 0:00
15s threshold

The whole class handling layer of our app is five lines:

import { type ClassValue , clsx } from " clsx " import { twMerge } from " tailwind-merge "

export function cn (... inputs : ClassValue []) { return twMerge ( clsx ( inputs )) }

Enter fullscreen mode

Exit fullscreen mode

That is lib/utils.ts , the file every shadcn/ui install drops in, used at 54 call sites across 18 files here. Two dependencies, one function, zero configuration. I wanted to know what it actually produces in production, so I fetched all 72 URLs from pub-trivia.app/sitemap.xml and counted.

What 72 pages of Tailwind weigh

HTML, all 72 pages 5,081,245 bytes class attributes 13,379 bytes inside them 674,045 (13.3% of the HTML) distinct class strings 324

Enter fullscreen mode

Exit fullscreen mode

Thirteen per cent of every byte we serve is the contents of class . That number sounds like an indictment and is not, because of the third line: 13,379 attributes are built from 324 unique strings.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.