Mobile app version of vmapp.org
Login or Join
Ann8826881

: Using gzip to compress assets 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

@Ann8826881

Posted in: #Gzip

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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Ann8826881

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ravi8258870

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: developers.google.com/speed/articles/gzip

10% popularity Vote Up Vote Down


 

@Speyer207

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme