2023-06-09
2460
#css
Hamsa Harcourt
84343
Jun 9, 2023 â‹… 8 min read

Guide to removing unused CSS code with PurgeCSS

Hamsa Harcourt I'm Hamsa, a software engineer with a strong passion for building human-centric products. I love teaching concepts about JavaScript and the web at large.

Recent posts:

Build A Micro-Frontend Application With React

Build a micro-frontend application with React

Learn to build scalable micro-frontend applications using React, discussing their advantages over monolithic frontend applications.

Harsh Patel
Nov 4, 2024 â‹… 8 min read
Building A Real-Time Chat App Using Laravel Reverb And Vue

Building a real-time chat app using Laravel Reverb and Vue

Build a fully functional, real-time chat application using Laravel Reverb’s backend and Vue’s reactive frontend.

Rosario De Chiara
Nov 4, 2024 â‹… 12 min read
Solving The Node.js Console.Time Is Not A Function Error

Solving the Node.js console.time is not a function error

Explore the two variants of the `console.time is not a function` error, their possible causes, and how to debug.

Joseph Mawa
Nov 1, 2024 â‹… 6 min read
Why jQuery 4 Is A Good Reminder To Stop Using jQuery

Why jQuery 4 is a good reminder to stop using jQuery

jQuery 4 proves that jQuery’s time is over for web developers. Here are some ways to avoid jQuery and decrease your web bundle size.

Shalitha Suranga
Oct 31, 2024 â‹… 11 min read
View all posts

6 Replies to "Guide to removing unused CSS code with PurgeCSS"

    1. Keep in mind that PurgeCSS doesn’t touch your source CSS files, just the ones that are output by the build process. So if you add new code that needs CSS rules that were previously purged, then the next time you build your app PurgeCSS will see that your code is using some new rules and will not purge them in that build.

  1. In frameworks such as Angular, you can use scss which is complied down to css. Is there any way to achieve this on scss?

    1. It doesn’t make sense to run it on SCSS because other SCSS files might be referencing your code dynamically elsewhere. You can transpile it to CSS, then run the process on CSS as part of your CI pipeline or have a local git hook to do so. It has the same effect.

Leave a Reply