Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'd like to check if i understand gzip compression correctly, i learned about it only recently. I'm working on an asset manager for an HTML5 game currently. On my end as a front-end developer, i can do all my logic as normal? When i need an .mp3 file, i can request a .mp3 using the audio tag, when i need a text file, i can request a text file from the server using XHR, it's the server that will read the request, compress the response, send it compressed, then the browser will unpack it and i'll get the file. Correct?

Also, is there a way to store already-compressed assets on the server and make Apache/etc. figure out which compressed file to send back to the browser without me making any changes to my code?

This is probably a very lazy approach to the issue, but right now i'd just like to make sure that i'm not going to have to rewrite my asset manager when switching from development to deployment.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Apache uses deflate which is responsible for compressing the data into gzip formatting and sending it to the client, its important to note that the compress happens as the data is requested and not before. You should familiarize yourself with mod_deflate as well ensure its installed and enabled correctly.

Formats such as MP3 are not ideal for gzip since they are already compressed and this would add additional resources to a pointless task, text based files are not compressed and very ideal for this gzip. You can specify formats by using the following code:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Notice how all the above are all TEXT based - as mentioned before do not attempt to compress heavy files as this is likely to delay your server and make it slower.

You should check this guide out about optimizing your site with Gzip.

Compressing Data Before Sending It

Some data can be compressed before you send it - mp3's and videos are already compressed in mp3 formating, and mp4 or any other video format. The text files such as HTML, CSS can only be compressed using gzip as I know but you can minify it and make the files even smaller. If you have a VPS then you can install Google Modspeed which is an Apache module that gzips, minifiys and even combines js, css files.

Additional You May Find These Links Useful

Online JavaScript/CSS Compression Using YUI Compressor is useful for combinging CSS files with one another so that you are reducing the server side requests, this can also be applied to your JavaScript.

Smushit is a Yahoo project and makes it easy to compress your PNG/Jpeg/Gif files even smaller without losing any quality over your original compression settings. It uses a lossless compression.

share|improve this answer
    
Exactly what I had already half-written! –  Itai Mar 18 '13 at 17:09
1  
type faster.. ;) –  bybe Mar 18 '13 at 17:18
    
Probably worth remarking, for clarity, that you can pre-gzip HTML, CSS, JS etc and save them as .html.gz, .css.gz, etc, and have the server serve those files, adding the appropriate headers etc. Apache (by default) will not cache a gzipped file -- it will gzip for each and every request. –  Brendon Mar 21 '13 at 11:57
add comment

You don't have to worry about gzip. It's the browser's job to uncompress them and there isn't anything you have to do differently.

Short read: https://developers.google.com/speed/articles/gzip

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.