Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Apache cache the gzipped version of a static file?

If you configure Apache to enable gzip compression for your static HTML/CSS/JS/etc. files, it automatically outputs a gzipped version to any client that sends an appropriate Accept-Encoding request header. (And for other clients, it just sends the raw uncompressed file.)

My question is: does Apache recompress the raw file every time it is requested by a gzip-accepting client? Or does it cache the gzipped copy, and only recompress it if it notices the last-modified time on the file has changed?

And if it does cache a gzipped copy of your files, where is this cache stored?

like image 862
callum Avatar asked Jun 17 '11 13:06

callum


People also ask

How do you check if files are Gzipped?

gzip compressed files often have the . gz file extension (in fact, I don't think I've ever seen a . gzip extension), but it's generally unsafe to rely on file extension to test for the type of file anyhow. The c 'library' gzip, ie gzopen/gzread/etc will transparently read uncompressed files.

What is Gzipped file?

GZIP, short for GNU Zip, is a compression/decompression format developed as part of a larger project to create a free software alternative to UNIX in the 1980s. This open source compression format does not support archiving, so it is used to compress single files. GZIP produces zipped files with the . gz extension.

Are GZ files compressed?

A GZ file is an archive file compressed by the standard GNU zip (gzip) compression algorithm. It typically contains a single compressed file but may also store multiple compressed files. gzip is primarily used on Unix operating systems for file compression.

How do I enable gzip in Apache?

To turn on Gzip compression, simply add on to the gzip directive in the main Nginx configuration file. $ sudo nano /etc/nginx/nginx. conf gzip on; Add file types to compress.


2 Answers

No it doesn't cache the gzipped file.

However the cost of compressing the file is less than the cost of squirting the extra packets across the network, hence even without caching you will see lower overall CPU usage (and lower memory usage, and fewer context switches) on your server - and a faster response at the client.

Note that the compressed file is NOT stored in the temp folder - mod_deflate reads input into a fixed size buffer in memory - and when the buffer is full (or the stream ends) the content is compressed and handed back to the webserver.

It will use even less CPU (although speed won't improve noticably) if the content is pre-compressed or cached serverside - there's multiple ways of doing this - mod_rewrite can test for the presence of filename.gz and serve it up in place of filename or you can use a reverse proxy (assuming the content is also served up with caching instructions).

like image 81
symcbean Avatar answered Oct 22 '22 04:10

symcbean


No, it does not. This is described in the mod_deflate documentation now:

Since mod_deflate re-compresses content each time a request is made, some performance benefit can be derived by pre-compressing the content and telling mod_deflate to serve them without re-compressing them.

like image 37
cweiske Avatar answered Oct 22 '22 03:10

cweiske