Web browsers aren’t concerned about the readability of code or how beautiful they are written. What matters is the code shouldn't have any errors. So, to reduce website load time web designers/developers or even bloggers will in most cases minify the JS files of their website.
Unlike traditional compression techniques, minified files don’t need to be decompressed before they can be read, modified or executed. Minification is performed after the code for a web application is written, but before the application is deployed. When a user requests a webpage, the minified version is sent instead of the full version, resulting in faster response times and lower bandwidth costs. Minification is used in websites ranging from small personal blogs to multi-million user services.
Minification works by analyzing and rewriting the text-based parts of a website to reduce its overall file size. Minification extends to scripts, style sheets, and other components that the web browser uses to render the site.
Minification is performed on the webserver before a response is sent. After minification, the web server uses the minified assets in place of the original assets for faster distribution to users.
Here’s a step-by-step description of how minification works:
- The developer applies a minification technique (see below) to convert the file into one that’s more optimized, but harder to read. Common minification techniques include removing whitespace, shortening variable names, and replacing verbose functions with shorter, more concise functions.
- The web server uses the minified file when responding to web requests, resulting in lower bandwidth usage without sacrificing functionality.
The benefit of minification is that it only needs to be performed when the source file changes. When combined with other compression techniques, minification can greatly reduce bandwidth usage for both the enterprise and the user.
Benefits of Minification
- Users load content faster as less unnecessary data needs to be downloaded. Users experience identical services without the additional overhead.
- Businesses see lower bandwidth costs as less data is transmitted over the network. The extra content that only developers care about is no longer being sent to users.
- Businesses also see lower resource usage since less data needs to be processed for each request. The minified content – which only needs to be generated once – can be used for an unlimited number of requests.