Open In App

How to Improve Performance by Minify & Compress Files ?

Minification is a very widely recognized and useful process that helps us to improve the performance of a web application by removing the unnecessary parts, generally the whitespaces, line-breaks and comments from the HTML, CSS and JavaScript files.

Minification: It is the process of minimizing the size of a code or markup files inside your web application without changing the behavior and output of the application. In simple words, minification is the method of removing all the unnecessary things including whitespaces and comments from HTML, CSS, and JavaScript code that do not affect our output. It reduces the project size and improves performance.



How does minification work?

Methods of minification: There are generally three methods by which we can minify our HTML, CSS, and JavaScript files. They are



 

Editor extensions: Different extensions that the code editors like Visual Studio Code or Atom provide can also be very helpful and generate a minified version of the HTML, CSS, or JavaScript codes automatically. Google search according to the specific editor you use is going to show you the path to do it. JS & CSS Minifier (Minify) by olback is one of the most popular JavaScript and CSS minifier extensions at Visual Studio Code.

Advantages of minification: The main aspect of minification is that it reduces the size of the web application. That brings many advantages. They are as follows

Example:

HTML:

 

CSS:

JavaScript:

The Change in Output: Now we are going to check that if there is any change in output due to the minification of the CSS files. We are going to keep the HTML document unchanged throughout the examples.

Before Minification:




<!DOCTYPE html>
<html>
<head>
  <title>GFG</title>
  <style>
  body {
    background-color: #282c34;
    color: white;
    padding: 40px;
    font-family: Arial;
    text-align: center;
  }
  </style>
</head>
<body>
  <h2>Welcome To GFG</h2>
  <p>How to improve performance by Minify and Compress Files</p>
</body>
</html>

Output:

After Minification:




<!DOCTYPE html>
<html>
<head>
  <title>GFG</title>
  <style>body{background-color:#282c34;color:#fff;padding:40px;font-family:Arial;text-align:center}
  </style>
</head>
<body>
  <h2>Welcome To GFG</h2>
  <p>How to improve performance by Minify and Compress Files</p>  
</body>
</html>

Output:


Article Tags :