Minification
Minification is the process of removing everything a browser does not need from code files, such as spaces, line breaks, comments and long names, to make CSS, JavaScript and HTML smaller and faster to download.
Developers write code with indentation, comments and descriptive names so people can read it. Browsers do not need any of that. Minification strips it out automatically, producing a compact file that works exactly the same. It is usually done as part of a site's build or by a performance plugin, never by hand.
Minification is often confused with compression. Compression, such as gzip or Brotli, is applied by the server as files are sent and reversed by the browser on arrival. Minification permanently rewrites the file to be shorter. They work well together, and most fast sites use both.
How it works
A minifier reads the code and rewrites it without changing what it does. For CSS, it removes spaces and line breaks, deletes comments, shortens colour values and merges duplicate rules. For JavaScript, it can go further, renaming internal variables to single letters and removing code that can never run. For HTML, it trims whitespace and optional parts.
Minification usually runs automatically, either in the build step of a modern site, often within a CI/CD pipeline, or through a caching or performance plugin on a CMS. Developers keep the readable original and deploy the minified version. A file called a source map can link the two, so errors in the minified code can still be traced back to the readable source.
The savings depend on the file. Heavily commented, spaciously written files shrink a lot; files that are already compact shrink little. Minification also does nothing about code the page does not use at all, which is often the bigger problem on sites with large themes and many plugins. Removing unused code, sometimes called tree shaking when a build tool does it automatically for JavaScript, usually saves more than minification, and the two are often run in the same build step.
Example
A WordPress site for a physiotherapy clinic loads a dozen stylesheets and scripts from its theme and plugins, all in their readable form. PageSpeed Insights flags them as unminified. The developer enables minification in the site's caching plugin, and the files shrink without any visible change to the site.
The plugin also offers to combine all files into one and defer scripts. With every option switched on, the booking widget stops working, because one script now loads before another it depends on. The developer keeps minification on, excludes the booking script from the deferral setting and tests the booking flow before and after each change. The site ends up lighter and the booking widget works, and the developer notes which settings were changed so the next person maintaining the site knows why the exclusion exists.
Why it matters for your business
Minification is a low-effort, low-risk improvement that makes pages slightly faster for every visitor, and it is usually one setting in a performance plugin or a standard part of a modern build. It will not rescue a slow site on its own, because large images, too many scripts and slow hosting matter more. The main risk comes from aggressive optimisation options bundled alongside it, so test key pages, forms and checkouts after turning them on, and switch off any option that breaks something.
Common mistakes
- Switching on every optimisation option in a plugin at once and not noticing what broke.
- Editing minified files directly on the server instead of the readable source.
- Expecting minification to fix a slow site that is really held back by images or third-party scripts.
- Minifying files twice through two different plugins and creating hard-to-trace conflicts.
Questions people ask
What is the difference between minification and compression?
Minification rewrites code files permanently, removing spaces, comments and long names. Compression, such as gzip or Brotli, is applied by the server when files are sent and undone by the browser on arrival. They are complementary, and most fast sites use both.
Can minification break my website?
Minification on its own rarely breaks anything, because the code does exactly the same thing. Problems usually come from related options, such as combining or deferring scripts, which can change the order code runs in. Test important pages after changing these settings.
How do I check if my site is minified?
Run a page through Google PageSpeed Insights, which lists CSS and JavaScript files that could be minified. You can also open a stylesheet or script address in the browser: minified files appear as long unbroken lines with no comments or indentation.