SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Tree shaking your CSS
Or does your CSS tree shake you?
• What is tree shaking? 1
1 
source: http://geekwagon.net/projects/xkcd1190/?
frame=2142
• What is tree shaking?
• What is the benefit?
• What is tree shaking?
• What is the benefit?
• Are you a tree shaker?
How CSS goes IRL...
•Add something like Bootstrap (Maybe
with NPM)
•Use some bits of it
•Write copy-paste some CSS
Maybe you get fancy
•Custom Bootstrap generation
•Some Framework specific
implementation (Reactstrap)
•Add a Sass or Less build pipeline
Worst case
•Start dropping combinations of
frameworks
•Can I use Bootstrap with Material with...
•Not knowing what CSS CDN imports are
doing
A good process
•Start with CDN if you don't have a starter
project
•As you move towards production and
testing create a build process
•KISS
Some good tools
•Gulp.js (or Grunt) Autoprefixer
•Sass and node-sass
•Start build buliding a single file
MYTH! CSS Framework Bloat
•Most modern projects are modular by
nature: ZURB Foundation, Bootstrap, etc.
•These options are turned off by default
•If you use customize Bootstrap you are
already doing this
Just a tool not a process
•Take what you want, leave the rest
•Good examples of large project
architecture
•Are the largest and most widely used
Design Systems in the world
Whats the situation
wget https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css
du -hs bootstrap.min.css
144K bootstrap.min.css
npm install bootstrap
du -hs node_modules/bootstrap/dist/css/bootstrap.min.css
140K node_modules/bootstrap/dist/css/
bootstrap.min.css
Bootstrap Sass "blanket" import
@import "bootstrap";
136K dist/assets/css/app.css
Minimalism in Bootstrap
@import "functions";
@import "variables";
@import "mixins";
@import "root";
@import "reboot";
@import "type";
@import "images";
@import "grid";
@import "tables";
@import "forms";
@import "buttons";
@import "badge";
@import "alert";
@import "close";
@import "modal";
52K dist/assets/css/app.css
Mixins only ZERO CSS
@import "functions";
@import "variables";
@import "mixins";
0B dist/assets/css/app.css
BlueprintJS
yarn add @blueprintjs/core react react-dom
blueprintjs › du -hs node_modules/normalize.css/normalize.css
8.0K node_modules/normalize.css/normalize.css
blueprintjs › du -hs node_modules/@blueprintjs/icons/lib/css/blueprint-icons.css
4.0K node_modules/@blueprintjs/icons/lib/css/blueprint-icons.css
blueprintjs › du -hs node_modules/@blueprintjs/core/lib/css/blueprint.css
296K node_modules/@blueprintjs/core/lib/css/blueprint.css
308k Total
The Nuclear Option
UNCSS
The Nuclear Option
Except...
UnCSS only runs the Javascript that is run
on page load. It does not (and cannot)
handle Javascript that runs on user
interactions like button clicks. 2
2 
source: https://www.npmjs.com/package/uncss
Except (Cont.)...
You must use the ignore option to
preserve classes that are added by
Javascript on user interaction. 2
2 
source: https://www.npmjs.com/package/uncss
There is an
easier way
James Stone in Finland
According to LinkedIn, I am the only one at the moment...
@JamesStoneCo @ComposingCode

Weitere ähnliche Inhalte

Was ist angesagt?

Drupal and Elasticsearch - The "new school" search engine
Drupal and Elasticsearch - The "new school" search engineDrupal and Elasticsearch - The "new school" search engine
Drupal and Elasticsearch - The "new school" search engine
Nikolay Ignatov
 
Rails Performance Tricks and Treats
Rails Performance Tricks and TreatsRails Performance Tricks and Treats
Rails Performance Tricks and Treats
Marshall Yount
 
Itlc hanoi lesson learned-open-stack - pham tung duong
Itlc hanoi lesson learned-open-stack - pham tung duongItlc hanoi lesson learned-open-stack - pham tung duong
Itlc hanoi lesson learned-open-stack - pham tung duong
Le Cuong
 

Was ist angesagt? (20)

Automating Cloud Cluster Deployment: Beyond the Book
Automating Cloud Cluster Deployment: Beyond the BookAutomating Cloud Cluster Deployment: Beyond the Book
Automating Cloud Cluster Deployment: Beyond the Book
 
Php johannesburg meetup - talk 2014 - scaling php in the enterprise
Php johannesburg   meetup - talk 2014 - scaling php in the enterprisePhp johannesburg   meetup - talk 2014 - scaling php in the enterprise
Php johannesburg meetup - talk 2014 - scaling php in the enterprise
 
Drupal and Elasticsearch - The "new school" search engine
Drupal and Elasticsearch - The "new school" search engineDrupal and Elasticsearch - The "new school" search engine
Drupal and Elasticsearch - The "new school" search engine
 
Node.js primer
Node.js primerNode.js primer
Node.js primer
 
Going Node.js at Netflix
Going Node.js at NetflixGoing Node.js at Netflix
Going Node.js at Netflix
 
Automated perf optimization - jQuery Conference
Automated perf optimization - jQuery ConferenceAutomated perf optimization - jQuery Conference
Automated perf optimization - jQuery Conference
 
Building fast aspnet websites
Building fast aspnet websitesBuilding fast aspnet websites
Building fast aspnet websites
 
Javascript for Wep Apps
Javascript for Wep AppsJavascript for Wep Apps
Javascript for Wep Apps
 
Rails Performance Tricks and Treats
Rails Performance Tricks and TreatsRails Performance Tricks and Treats
Rails Performance Tricks and Treats
 
Dev/Test in the Cloud - F
Dev/Test in the Cloud - FDev/Test in the Cloud - F
Dev/Test in the Cloud - F
 
Atomic Design with Next.js
Atomic Design with Next.jsAtomic Design with Next.js
Atomic Design with Next.js
 
Elasticsearch PHP UG BG
Elasticsearch PHP UG BGElasticsearch PHP UG BG
Elasticsearch PHP UG BG
 
Immutable servers with Packer/Chef/AWS
Immutable servers with Packer/Chef/AWSImmutable servers with Packer/Chef/AWS
Immutable servers with Packer/Chef/AWS
 
Maksym Khamrovskyi, Kostiantyn Averin "Octopus: on the way to deployment bril...
Maksym Khamrovskyi, Kostiantyn Averin "Octopus: on the way to deployment bril...Maksym Khamrovskyi, Kostiantyn Averin "Octopus: on the way to deployment bril...
Maksym Khamrovskyi, Kostiantyn Averin "Octopus: on the way to deployment bril...
 
Seven Jobs You Should Be Running #sqlsat126
Seven Jobs You Should Be Running #sqlsat126Seven Jobs You Should Be Running #sqlsat126
Seven Jobs You Should Be Running #sqlsat126
 
Ready? Bootstrap! Go! (CFUG Belgium 24 04-2012)
Ready? Bootstrap! Go! (CFUG Belgium 24 04-2012)Ready? Bootstrap! Go! (CFUG Belgium 24 04-2012)
Ready? Bootstrap! Go! (CFUG Belgium 24 04-2012)
 
Cvcc performance tuning
Cvcc performance tuningCvcc performance tuning
Cvcc performance tuning
 
How to build a static website in two and a half days with Nuxt and Tailwind CSS
How to build a static website in two and a half days with Nuxt and Tailwind CSSHow to build a static website in two and a half days with Nuxt and Tailwind CSS
How to build a static website in two and a half days with Nuxt and Tailwind CSS
 
Itlc hanoi lesson learned-open-stack - pham tung duong
Itlc hanoi lesson learned-open-stack - pham tung duongItlc hanoi lesson learned-open-stack - pham tung duong
Itlc hanoi lesson learned-open-stack - pham tung duong
 
Azure Saturday 2017 - Planning for the Cloud
Azure Saturday 2017 - Planning for the CloudAzure Saturday 2017 - Planning for the Cloud
Azure Saturday 2017 - Planning for the Cloud
 

Ähnlich wie Treeshaking your CSS

Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 

Ähnlich wie Treeshaking your CSS (20)

Rapid and Responsive - UX to Prototype with Bootstrap
Rapid and Responsive - UX to Prototype with BootstrapRapid and Responsive - UX to Prototype with Bootstrap
Rapid and Responsive - UX to Prototype with Bootstrap
 
FITC - Bootstrap Unleashed
FITC - Bootstrap UnleashedFITC - Bootstrap Unleashed
FITC - Bootstrap Unleashed
 
Know the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css frameworkKnow the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css framework
 
Intro to html5 Boilerplate
Intro to html5 BoilerplateIntro to html5 Boilerplate
Intro to html5 Boilerplate
 
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
Scalable front-end architecture with Bootstrap 3 + Atomic CSSScalable front-end architecture with Bootstrap 3 + Atomic CSS
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
 
It's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrIt's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking Modernizr
 
Going on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web PerformanceGoing on an HTTP Diet: Front-End Web Performance
Going on an HTTP Diet: Front-End Web Performance
 
Webpack and Web Performance Optimization
Webpack and Web Performance OptimizationWebpack and Web Performance Optimization
Webpack and Web Performance Optimization
 
CSS framework By Palash
CSS framework By PalashCSS framework By Palash
CSS framework By Palash
 
BDUG Responsive Web Theming - 7/23/12
BDUG Responsive Web Theming - 7/23/12BDUG Responsive Web Theming - 7/23/12
BDUG Responsive Web Theming - 7/23/12
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overview
 
CSS Workflow. Pre & Post
CSS Workflow. Pre & PostCSS Workflow. Pre & Post
CSS Workflow. Pre & Post
 
Building the next generation of themes with WP Rig 2.0
Building the next generation of themes with WP Rig 2.0Building the next generation of themes with WP Rig 2.0
Building the next generation of themes with WP Rig 2.0
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tips
 
Battle of the Front-End Frameworks: Bootstrap vs. Foundation
Battle of the Front-End Frameworks: Bootstrap vs. FoundationBattle of the Front-End Frameworks: Bootstrap vs. Foundation
Battle of the Front-End Frameworks: Bootstrap vs. Foundation
 
Untangling the web - fall2017 - class 4
Untangling the web - fall2017 - class 4Untangling the web - fall2017 - class 4
Untangling the web - fall2017 - class 4
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in Production
 
HTML5, just another presentation :)
HTML5, just another presentation :)HTML5, just another presentation :)
HTML5, just another presentation :)
 
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkNot Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
 

Mehr von James Stone

Turku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-componentsTurku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-components
James Stone
 
Canvas Only: Creative Coding in HTML5
Canvas Only: Creative Coding in HTML5Canvas Only: Creative Coding in HTML5
Canvas Only: Creative Coding in HTML5
James Stone
 

Mehr von James Stone (7)

Turku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-componentsTurku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-components
 
Easy Bolt-on Docs Using React Styleguidist
Easy Bolt-on Docs Using React StyleguidistEasy Bolt-on Docs Using React Styleguidist
Easy Bolt-on Docs Using React Styleguidist
 
Living Styleguides: Build Your Own Bootstrap
Living Styleguides: Build Your Own BootstrapLiving Styleguides: Build Your Own Bootstrap
Living Styleguides: Build Your Own Bootstrap
 
ZURB Foundation 5: Clean + Organized
ZURB Foundation 5: Clean + OrganizedZURB Foundation 5: Clean + Organized
ZURB Foundation 5: Clean + Organized
 
Wordpress -> Middleman: Lesson learned in the 2-years since migrating
Wordpress -> Middleman: Lesson learned in the 2-years since migratingWordpress -> Middleman: Lesson learned in the 2-years since migrating
Wordpress -> Middleman: Lesson learned in the 2-years since migrating
 
ZURB Foundation 5 -- Understanding the Ecosystem
ZURB Foundation 5 -- Understanding the EcosystemZURB Foundation 5 -- Understanding the Ecosystem
ZURB Foundation 5 -- Understanding the Ecosystem
 
Canvas Only: Creative Coding in HTML5
Canvas Only: Creative Coding in HTML5Canvas Only: Creative Coding in HTML5
Canvas Only: Creative Coding in HTML5
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Treeshaking your CSS

  • 1. Tree shaking your CSS Or does your CSS tree shake you?
  • 2. • What is tree shaking? 1 1  source: http://geekwagon.net/projects/xkcd1190/? frame=2142
  • 3. • What is tree shaking? • What is the benefit?
  • 4. • What is tree shaking? • What is the benefit? • Are you a tree shaker?
  • 5. How CSS goes IRL... •Add something like Bootstrap (Maybe with NPM) •Use some bits of it •Write copy-paste some CSS
  • 6. Maybe you get fancy •Custom Bootstrap generation •Some Framework specific implementation (Reactstrap) •Add a Sass or Less build pipeline
  • 7. Worst case •Start dropping combinations of frameworks •Can I use Bootstrap with Material with... •Not knowing what CSS CDN imports are doing
  • 8. A good process •Start with CDN if you don't have a starter project •As you move towards production and testing create a build process •KISS
  • 9. Some good tools •Gulp.js (or Grunt) Autoprefixer •Sass and node-sass •Start build buliding a single file
  • 10. MYTH! CSS Framework Bloat •Most modern projects are modular by nature: ZURB Foundation, Bootstrap, etc. •These options are turned off by default •If you use customize Bootstrap you are already doing this
  • 11. Just a tool not a process •Take what you want, leave the rest •Good examples of large project architecture •Are the largest and most widely used Design Systems in the world
  • 12. Whats the situation wget https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css du -hs bootstrap.min.css 144K bootstrap.min.css npm install bootstrap du -hs node_modules/bootstrap/dist/css/bootstrap.min.css 140K node_modules/bootstrap/dist/css/ bootstrap.min.css
  • 13. Bootstrap Sass "blanket" import @import "bootstrap"; 136K dist/assets/css/app.css
  • 14. Minimalism in Bootstrap @import "functions"; @import "variables"; @import "mixins"; @import "root"; @import "reboot"; @import "type"; @import "images"; @import "grid"; @import "tables"; @import "forms"; @import "buttons"; @import "badge"; @import "alert"; @import "close"; @import "modal"; 52K dist/assets/css/app.css
  • 15. Mixins only ZERO CSS @import "functions"; @import "variables"; @import "mixins"; 0B dist/assets/css/app.css
  • 16. BlueprintJS yarn add @blueprintjs/core react react-dom blueprintjs › du -hs node_modules/normalize.css/normalize.css 8.0K node_modules/normalize.css/normalize.css blueprintjs › du -hs node_modules/@blueprintjs/icons/lib/css/blueprint-icons.css 4.0K node_modules/@blueprintjs/icons/lib/css/blueprint-icons.css blueprintjs › du -hs node_modules/@blueprintjs/core/lib/css/blueprint.css 296K node_modules/@blueprintjs/core/lib/css/blueprint.css 308k Total
  • 19. Except... UnCSS only runs the Javascript that is run on page load. It does not (and cannot) handle Javascript that runs on user interactions like button clicks. 2 2  source: https://www.npmjs.com/package/uncss
  • 20. Except (Cont.)... You must use the ignore option to preserve classes that are added by Javascript on user interaction. 2 2  source: https://www.npmjs.com/package/uncss
  • 22. James Stone in Finland According to LinkedIn, I am the only one at the moment... @JamesStoneCo @ComposingCode