{"id":205543,"date":"2015-07-27T10:16:24","date_gmt":"2015-07-27T17:16:24","guid":{"rendered":"http:\/\/css-tricks.com\/?p=205543"},"modified":"2015-07-27T10:16:24","modified_gmt":"2015-07-27T17:16:24","slug":"the-difference-between-minification-and-gzipping","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/the-difference-between-minification-and-gzipping\/","title":{"rendered":"The Difference Between Minification and Gzipping"},"content":{"rendered":"
These are both things that you do to assets on your website (things like .css files and .js files). They are both things that reduce the size of the file, making it more efficient in crossing the network between servers and browsers. As in, good for performance. The network is the speed bottleneck of the web and reducing file size helps.<\/p>\n
But these two things are distinctly different. If you didn’t already know that, it’s worth understanding.<\/p>\n
<\/p>\n
… and stuff like that. The file remains perfectly valid code. You wouldn’t want to try to read it or work with it, but it’s not breaking any rules. The browser can read it and use it just like it could the original file.<\/p>\n
Minification creates a new file that you ultimately use. For instance, you’d create a `style.css` that you work with. Then you could minify it into `style.min.css`.<\/p>\n
Julia Evans created a wonderful way to understand this (see her post and video<\/a>). See this first paragraph of a poem:<\/p>\n \nOnce upon a midnight dreary, while I {pon}<\/span>dered weak an{d wea}<\/span>{ry,}<\/span> The text within the curly brackets has been discovered by gzip to be repetitive. Thus will be replaced with a pointer that uses less space than the text itself does.<\/p>\n This can be incredibly effective at reducing file size, especially with code, since code be incredibly repetitive. Imagine how many instances of You can create gzipped version of files (i.e. style.css.zip) but you rarely ever do that<\/strong> and the browser won’t know what to do with it<\/strong>. <\/p>\n On the web, gzipping is done directly by your server. It’s a matter of configuring the server to do it. Once that’s done, gzipping automatically happens, there isn’t any ongoing work you have to do. The server compresses the file and sends it across the network like that. The browser receives the file and unzipped it before using it. I’ve never heard anyone mention anything about the overhead of zipping and unzipping, so I just assume it’s negligible and the benefits far outweigh the overhead.<\/p>\n Here’s how to enable it on Apache servers<\/a>, where it uses the We’ll use the CSS file from Bootstrap<\/a> since it’s such a common asset.<\/p>\n
\nOver many{ a }<\/span>quaint{ and }<\/span>curious volume of forgotten lore,
\nW{hile I }<\/span>nodded, n{ear}<\/span>ly napping, su{dde}<\/span>n{ly }<\/span>th{ere}<\/span> ca{me }<\/span>a t{apping,}<\/span>
\nAs{ of }<\/span>so{me o}<\/span>ne gent{ly }<\/span>r{apping, }<\/span>{rapping}<\/span> at my chamb{er }<\/span>door.
\n`’Tis{ some }<\/span>visitor,’{ I }<\/span>mu{tte}<\/span>r{ed, }<\/span>`t{apping at my chamber door}<\/span> –
\nO{nly th}<\/span>is,{ and }<\/span>no{thi}<\/span>{ng }<\/span>m{ore}<\/span>.\n<\/p><\/blockquote>\n<div <\/code> there are in an HTML file or
{ <\/code> in a CSS file.<\/p>\n
mod_deflate<\/code> module. And H5BP offers server configurations<\/a> for all the popular servers that include gzipping.<\/p>\n
An Example<\/h3>\n