Minification is the process of minimizing code and markup in web pages and script files without changing its functionality. It strips a code file of all data that isn’t required in order for the file to be executed. Unlike other compression techniques, minified files don’t need to be decompressed before being read, modified, or executed. Minification is used to reduce load times and bandwidth usage on websites. It greatly improves site speed and accessibility, meaning user experience is also improved.
var array = ; for (var i = 0; i
The minified version is equivalent to the original code but is much shorter:
How minification works
Minification is done after the code for a web application is written but before the application is deployed. It works by analyzing and rewriting the text-based parts of a website to reduce its overall file size. After minification, the web server replaces the original assets with minified assets for faster distribution to users.
- Removing whitespace
- Shortening variable names
- Replacing verbose functions with more concise functions
Once minified, the web server uses the file when responding to web requests.
In some cases, minification can break complicated scripts because of site-dependent variables such as themes, plugins, and server environments. This may result in incorrect layouts or certain functions working incorrectly on a website. Minification can also introduce errors that are difficult to debug. While it can greatly reduce bandwidth usage and provide an increase in site speed, it should be used as a fine-tuning step, not the beginning step in improving a website.