SEO

Minification

Also called Minifying, minified files

Removing spaces, line breaks, comments and long names from code so the delivered file is smaller.

Quick facts: Minification

Category
SEO
Also called
Minifying, minified files
Level
Beginner
Affects
File size, download time, parse time, page speed scores
Where to see it
PageSpeed Insights, Chrome DevTools Sources panel, caching and build plugins
In this article4
  1. How minification works
  2. Why minification matters
  3. Where minification goes wrong
  4. Getting it right

How minification works

Source code is written for people. It carries indentation, blank lines, comments explaining decisions, and variable names chosen to be readable. A browser needs none of that. Minification produces a copy with all of it stripped out — and, in JavaScript, with internal names shortened — so the file that travels over the network is smaller while behaving identically.

It applies to CSS, JavaScript and HTML. The result is unreadable to a person, which is why the original is kept and the minified version is generated as part of publishing, either by a build step in a development workflow or by a caching plugin on a content management system.

Why minification matters

Smaller files arrive sooner, and that matters most for the ones in the critical path, since a render-blocking resource delays the first paint for exactly as long as it takes to fetch and read. There is a second, smaller gain in parsing: less text to work through means less time on the main thread, which counts on a modest phone.

It is also close to free. Unlike rewriting a theme or moving hosts, it is a switch. It changes no design and no content, and it can be reversed, which makes it a reasonable early move on almost any site.

Where minification goes wrong

The honest caveat is that the gain is modest once compression is enabled, because compression already handles repeated whitespace well. The two work together, but expecting minification alone to transform a slow site will disappoint. If a page is slow because it loads a great deal of code it never uses, removing the spaces from that code is not the answer.

Then there is breakage. Minifying files that were already minified, or combining scripts that depend on a particular order, produces errors that only show up on some pages — often the checkout, the enquiry form or an embedded map. Because the output is unreadable, the browser console points nowhere useful. This is why a caching plugin’s most aggressive preset should never be switched on across a live site without walking through it afterwards.

Getting it right

Turn it on where it is generated automatically: a build process on a custom site, or the optimisation settings of a caching plugin on WordPress. Keep the original source, and enable source maps if anyone debugs in the browser, so an error still points at a real line.

Then test properly. Load every template — home, service page, article, product, cart, contact — and complete a form and a purchase before deciding it worked. Enable one setting at a time rather than the whole panel at once, so you know what caused a break. And measure afterwards: if the figures barely move, file size was never the site’s problem, and the effort belongs in page speed optimisation that removes code rather than shrinking it.

Do and do not

Do

  • Minify CSS, JavaScript and HTML on the live site
  • Keep an unminified copy for debugging
  • Retest every page type after switching it on

Do not

  • Minify a file something else is already minifying
  • Assume minification replaces compression
  • Enable it and skip testing forms and checkout

Questions people ask about this

Is minification the same as compression?

No. Minification changes the file itself, removing characters a browser does not need, and the smaller file is what gets stored and served. Compression happens during transfer: the server packs the response, the browser unpacks it, and the file on disk is unchanged. Use both, because they solve different parts of the same problem.

Can minification break my website?

It can, particularly when scripts are also combined and their order changes, or when a file that was already minified is processed again. Forms, sliders, maps and checkout steps fail most often, and the error message is hard to read because the code is unreadable. Enable settings one at a time and test every page type.

Should I minify HTML as well?

You can, and it is usually harmless, but the return is smaller than for stylesheets and scripts because pages are often generated fresh and already compressed in transit. If your caching plugin offers it, leave it on and check that nothing depending on whitespace, such as pre-formatted code blocks, has changed appearance.

Related terms

Found this useful?

Share it, or ask an AI to summarise it

Back to the glossary

Knowing the term is the easy part

Applying it to your own site and budget is the work. Book a call and I will tell you what actually applies to you.