What Is Minification? Smaller Website Code Explained
Why does production website code look squashed together? It trims the code while keeping its intended behaviour.
1:47 · No narration: the video shows each step as text on screen, and every step is written out below, with buttons that jump the video to it.
Prefer YouTube? Watch this video on our YouTube channel (opens in a new tab).
The six points in the video
This is a silent video. The headings, explanations and labels below reproduce the information on screen.
-
Step 1: Start with the source file
Developers write readable code with spacing and useful comments.
On-screen labels: Readable source; Useful formatting; Editable project.
-
Step 2: Remove unnecessary characters
A minifier can strip whitespace and other non-essential text.
On-screen labels: Less whitespace; Removed comments; Smaller output.
-
Step 3: Preserve the behaviour
The built file should still perform its intended task.
On-screen labels: Same intended result; Valid output; Working interaction.
-
Step 4: Compression is another step
Minification and transfer compression can work together.
On-screen labels: Smaller source text; Compressed transfer; Separate techniques.
-
Step 5: Keep the original source
Future maintenance should use the editable project files.
On-screen labels: Original project; Version history; Rebuild process.
-
Step 6: Test the production build
Check the actual optimised files used by visitors.
On-screen labels: Important pages; Browser errors; Essential interactions.
A practical check for your business
Retain readable development sources and review the delivered production files separately. Check the resulting page after optimisation so a smaller script or stylesheet does not conceal a broken feature.
Sources and further detail
Common questions
Why does production website code look squashed together?
It trims the code while keeping its intended behaviour. Keep the editable source and test the built result.
Go further
More video tips
All 205 videos →
Image Aspect Ratios and Cropping: Keep the Important Subject Visible
Match the image to the space.
Bits and Bytes Explained: MB, Mb and Download Speeds
File sizes and transfer rates.