开发者

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开发者_C百科 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?


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).


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.


Apache does not keep any cached files. It only keeps the files you tell it to keep. Here is how compression works:

  1. Browser requests page and states it accepts compression
  2. Server finds page and reads the header of the request.
  3. Server sends page to the browser (compresses if stated it accepts in header request - compressed file is stored in memory/temp folder)
  4. Browser receives the information and displays (after decompression if compressed). The browser then caches the page and images.
  5. Server removes any hint of the compressed file from memory/temp folder to free up space for the next request. It does log in the access_log the transaction.

The browser when it requests the same file or page again. It sends a request to the server stating that it accepts compression, and the current files and Modified Date. From here the server would respond that they are the same and send no additional information, or send only the changed files based on the Modified Date.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜