What is minification?

Minification is the process of taking a file such as a stylesheet or a javascript file and removing all of the stuff that a browser doesn’t need to actually use the file.

Many times the team or individual that created a stylesheet will include comments, spacing between items, extra whitespace, and various other things that make the file easier to read for a human. But a browser does not need any of that to work properly and is why minification is a great way to easily save on file space.

How do I minify something?

There are command line tools, server side software, software plugins for frameworks such as WordPress, and web-based tools for CSS and JavaScript that can help you minify files.

I recommend using the CSS and JavaScript tools to create minified versions, and then name them the same thing, but append “min” to the end of the file.

For example, if I wanted to minify jQuery, a popular JavaScript library, the file names would look like this:

You can also click each of these to see what minification visually does to a file.

What will I gain?

While you most likely will not see any significant decrease in your bandwidth bill, the point of minification isn’t for the website owner, it is for the website visitor.

It has been proven in multiple studies that the faster your page is, the more time a user spends on your site which in many cases leads to more page views.

Some website owners see a reduction in size of up to 40%, and the average reduction is between 10-20% per minified file.

Are there any risks involved?

The risks are small, but when you minify something, an algorithm is ran against the file and things are removed from the file. Anytime something is removed from a file, you run the risk of something critical being removed from the file.

Personally, I have never experienced any of these problems, but as a programmer, I know how minification is performed and I would advise anyone only to use minification tools that are endorsed by authoritative figures.

All the tools linked in this blog post have been used personally by myself on most of the websites I develop and own.