Keep source files and a backup first

Minify CSS with a repeatable build

Do not edit .min.css by hand. Preserve readable source, configure a minification command and switch the website only after testing the generated file.

Safe CSS process: backup, minification, testing and publication
Backup → build → test → publish → verify again.

Message for a developer

“Save the CSS sources and current references. Configure reproducible minification without changing cascade order. Connect the minified builds with a new cache version, test key templates on desktop and mobile, and provide the rebuild command and before/after sizes.”

What to prepare

  • a backup of CSS, templates and build configuration;
  • key pages, forms, menus and interactive states;
  • a staging environment or reliable rollback;
  • CMS, Vite, Webpack, Gulp or other build-tool details.

Step-by-step

  1. Open Network → CSS in DevTools and record asset URLs and transferred sizes.
  2. Locate readable sources; never make a minified file the only editable copy.
  3. Create a test branch or staging copy and save current HTML references.
  4. Run a minifier on owned sources; do not blindly rewrite third-party assets without sources.
  5. Connect output in the same order and change the content hash or version parameter.
  6. Clear only relevant caches and test representative pages on desktop and mobile.
  7. Compare sizes, save the build command and publish.

Technical reference

A Node.js project can use a locally pinned dependency:

npm install --save-dev clean-css-cli
npx cleancss -o public/css/site.min.css resources/css/site.css

Do not combine files without checking order: later rules win when specificity is equal.

Rollback and verification

If styling disappears, restore previous references or backup files, reinstate the former cache version and purge the CDN. Check the console, CSS responses and asset order.

After publication, follow the independent verification guide. Unused CSS removal, Critical CSS, error repair and transfer compression are separate tasks. Without staging or a build pipeline, consider ordering the service.