Author Topic: Minifying and Gzipping text files for decreased size.  (Read 595 times)

Offline 133794m3r

  • Level 22
  • *
  • Posts: 265
  • Reputation: +2/-0
    • View Profile
Minifying and Gzipping text files for decreased size.
« on: February 07, 2010, 06:58:41 AM »
When using apache and the mod_gzip(i think that's the module's name if not whatever it's called). When you compress your files with gzip, and their extension changes to for example .js.gzip when it's called forth to the browser, does apache just automatically deflate it at once? Or does the  browser itself do it itself.  If anyone has any pages explaining how to do such a thing/wishes to explain how to do such a thing it'd be greatly appreciated.

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Minifying and Gzipping text files for decreased size.
« Reply #1 on: February 07, 2010, 07:09:25 AM »
Browser don't compress it, it wouldn't make sense, browser decompresses it

Common way:
Browser----request---->Server
Server----page----->Browser--->display

Server-side gzip via apache:
Browser---request---->Server
Server---gzip--->page--->Browser--decompress--->display

=> If you compress the file by yourself and save it that way (and don't use s-s gzipping), the gzip part in the last line is removed (not the "decompress" one)

However it's possible to have more layers of compression, like minified and packed file (for example JS library in shrinked version) and then s-s gzip....

It's most siginificant with JS files since they are usually large text files...the size drop is ....HUGE.
For example jQuery 1.4.1 is 156kB large (dev version), shrinked and gzipped version has final size of 23,5kB ...only 15% of total and 132,5kB less
The effect for example on image is quite minimal from what I've seen

You can view the downloaded size via Firefox's Firebug addon (Network tab)
« Last Edit: February 07, 2010, 07:56:16 AM by Nox »
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: Minifying and Gzipping text files for decreased size.
« Reply #2 on: February 07, 2010, 07:34:58 AM »
You can view the downloaded size via Firefox's Firebug addon (Network tab)

Just want to note that google chrome has a very nice "devtools" option for this stuff too. Just do: ctrl + shift + J

http://dev.chromium.org/devtools

Offline dsheroh

  • Level 21
  • *
  • Posts: 235
  • Reputation: +6/-0
  • Perl Vicar
    • View Profile
    • Psi Rangers
Re: Minifying and Gzipping text files for decreased size.
« Reply #3 on: February 07, 2010, 07:46:26 AM »
It's most siginificant with JS files since they are usually large text files...the size drop is ....HUGE.

The compression rates on HTML/CSS documents also tend to be excellent, as they tend to contain large amounts of repetitive text.  This site's main stylesheet, for example, gzips down from 8615 bytes to 2655, for a 70% reduction in file size.  Of course, being small to start with, it's still not that much of an overall benefit.

The effect for example on image is quite minimal from what I've seen

That's because common image file formats, such as JPEG, PNG, and GIF, are already compressed.  As an example, my current desktop wallpaper is a 1024x768 image with 24-bit color.  Uncompressed, it would be 1024 * 768 * 24 = 18,874,368 bits (2,359,296 bytes, or 2.25M).  As a .jpg, it's an 84k file.  That's about a 96.5% reduction in file size.  :)

If you're lucky, gzipping a compressed image file might net you another 1-2% reduction in file size - but it's at least as likely to make the file 1-2% bigger instead.

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Minifying and Gzipping text files for decreased size.
« Reply #4 on: February 07, 2010, 07:55:09 AM »
Thanks for adding the explanation
I mentioned JS because HTML/CSS are rather small so the absolute gain is not that big, but of course it's not bad, I compress them too

Quote
If you're lucky, gzipping a compressed image file might net you another 1-2% reduction in file size - but it's at least as likely to make the file 1-2% bigger instead.
Yes, plus you increase the overhead for the image so even if you got 1% reduction the effect would be imho rather negative
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal