3 ms·
I remember the first time I heard the word "tree shaking" for CSS. ...I genuinely wondered what tree was involved. Took a Google search before I understood tha
by knighthack 4y ago
I remember the first time I heard the word "tree shaking" for CSS.
...I genuinely wondered what tree was involved. Took a Google search before I understood that it was industry jargon, which meant this: to reduce/minify code.
There are many similarly opaque things in the world of web-development.
- splintercell 4y agoTree shaking doesn’t mean to minify the code but remove the CSS classes from the payload which are not being used anywhere. Proper term is dead code elimination (DCE).
- Jetrel 4y agoTo help clarify for the person you're replying to; minification could be considered to only mean: taking an interpreted language like JS, and essentially compressing the text of the code by doing transformations to it that don't change the semantic meaning of the code. Swapping out long variable/function names with short, computer-generated single(ish)-letter names. Removing whitespace. Much of this was because real compression methods like zip simply weren't available during early decades of web development. Obviously, if shrinking the code size is desirable, and you were building a library that did minification, you'd want to move on to also adding other, more dangerous changes that could change the meaning of the code, like removing unused CSS classes, doing DCE on javascript, etc, etc. -- Since programming is a giant, decentralized soup of autodidacts, there's no "word of god" authority that can really say "this is the one true name of something". It's mostly just lingo that passes in and out of various communities, and a lot of times communities (as you're seeing in splintercell's comment) try to helpfully match themselves up and standardize so it doesn't degenerate into pure chaos.
- redox99 4y agoWhy is "dead code elimination" more proper than tree shaking? Is CSS even "code"?
- TOGoS 4y agoDead Code Elimination is the goal. Tree Shaking is just one technique to achieve that goal.
- madeofpalk 4y agoTree shaking is not a web-development thing. Wikipedia says the term originally came from Lisp https://en.wikipedia.org/wiki/Tree_shaking https://en.wikipedia.org/wiki/Tree_shaking Every industry has things that have names that you might need to learn.
- redox99 4y agoImagine you have a root (let's say your index webpage). Then you can build a tree of what is used by what. So if you have a CSS classname that is used by C (C being an HTML element, component, whatever) and C is used by B, but B is not used by A (the root) then it's shaken (removed) and "falls" because it's not connected to the root. Basically remove everything not connected to the root.
- pessimizer 4y agoIf you're telling a story about how you learned something, it implies that you have learned it.