When a request is received from a client, Apache determines if mod_gzip should be invoked by noting whether the "Accept-Encoding" HTTP request header has been sent by the client. If the client sends the header (shown below), mod_gzip will compress the output of all configured file types when they're sent to the client.
Accept-encoding: gzip
This client header announces to Apache that the client will understand files that have been GZIP-encoded. mod_gzip then processes the outgoing content and includes the following server response headers.
Content-Type: text/html
Content-Encoding: gzip
These server response headers announce that the content returned from the server is GZIP-encoded, but that when the content is expanded by the client application, it should be treated as a standard HTML file. Not only is this successful for static HTML files, but it can also be applied to pages that contain dynamic elements, such as those produced by Server-Side Includes ( SSI), PHP, and other dynamic page generation methods. You can also use it to compress your Cascading Stylesheets ( CSS) and plain text files. My httpd.conf file sets the following configuration for mod_gzip:
mod_gzip_item_exclude file \.js$
mod_gzip_item_exclude mime ^text/css$
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.shtml$
mod_gzip_item_include file \.php$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include file \.txt$
mod_gzip_item_include mime ^text/plain$
mod_gzip_item_include file \.css$
mod_gzip_item_include mime ^text/css$
I've had limited success compressing other file formats, mainly because Microsoft's Internet Explorer appears to examine the "Content-Type" header message before it examines the "Content-Encoding" header message. So, say you configure your server to GZIP-encode PDF files using the following mod_gzip directives:
mod_gzip_item_include file \.pdf$
mod_gzip_item_include mime ^application/pdf$
This will work perfectly in both Mozilla and Opera, as these applications decode the GZIP-encoded content before they pass it along to the PDF reader (most people use Adobe Acrobat Reader).
However, Internet Explorer simply passes the GZIP-encoded content directly to the PDF reader. Once this issue is rectified in the MSIE code, you are likely to see a lot more Web servers serving a broader range of GZIP-encoded content.
--
With regards
没有评论:
发表评论