简体   繁体   English

我如何gzip我的网络文件

[英]How do I gzip my web files

As prescribed by Yahoo!, gzip'ng files would make your websites load faster. 按照Yahoo!的规定,gzip'ng文件会使您的网站加载更快。 The problem? 问题? I don't know how :p 我不知道如何:p

http://www.webcodingtech.com/php/gzip-compression.php http://www.webcodingtech.com/php/gzip-compression.php

Or if you have Apache, try http://www.askapache.com/htaccess/apache-speed-compression.html 或者如果你有Apache,请尝试http://www.askapache.com/htaccess/apache-speed-compression.html

Some hosting services have an option in the control panel. 某些托管服务在控制面板中有一个选项。 It's not always possible, though, so if you're having difficulty, post back with more details about your platform. 但是,这并不总是可行的,所以如果您遇到困难,请回复一下有关您平台的更多详细信息。

If you are running Java Tomcat then you set a few properties on your Connector ( in conf/server.xml ). 如果您正在运行Java Tomcat,那么您在Connector上设置了一些属性(在conf / server.xml中)。

Specifically you set: 具体你设置:

  1. compressableMimeType ( what types to compress ) compressableMimeType(要压缩的类型)
  2. compression ( off | on | ) 压缩(off | on |)
  3. noCompressionUserAgents ( if you don't want certain agents to receive gzip, list them here ) noCompressionUserAgents(如果您不希望某些代理接收gzip,请在此处列出)

Here's the tomcat documentation which discusses this: http://tomcat.apache.org/tomcat-5.5-doc/config/http.html 这是讨论这个的tomcat文档: http//tomcat.apache.org/tomcat-5.5-doc/config/http.html

Edit your httpd.conf file. 编辑httpd.conf文件。

Add this line to load the module: 添加此行以加载模块:

LoadModule deflate_module modules/mod_deflate.so

Add these lines to actually compress the output: 添加这些行以实际压缩输出:

AddOutputFilterByType DEFLATE text/css text/html application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Jetty will look for gzip'd versions of static files, as well as it has a GzipFilter for dynamic content. Jetty将寻找gzip版本的静态文件,并且它具有动态内容的GzipFilter。

You could probably pull the GzipFilter over into Tomcat if you wanted more control over compression than just Tomcat's connector-level compression... 如果你想要更多地控制压缩而不仅仅是Tomcat的连接器级压缩,你可以把GzipFilter拉到Tomcat中......

http://docs.codehaus.org/display/JETTY/GZIP+Compression http://docs.codehaus.org/display/JETTY/GZIP+Compression

Gzip compresses your webpages and cascade style sheets before sending them over to the client browser. Gzip压缩您的网页和级联样式表,然后将它们发送到客户端浏览器。

This drastically reduces transfer time since the files are much smaller. 这大大减少了传输时间,因为文件要小得多。

There are different methods of setting up gzip compression depending on whether or not you've got an IIS or Apache server 根据您是否拥有IIS或Apache服务器,有不同的设置gzip压缩的方法

Example: this link . 示例:此链接

Seeing how most answers here are almost 5 years old, here's some very current and up to date example references. 看看这里的大多数答案是近5年,这里有一些非常新的和最新的例子参考。

For example server configs that enable gzip/deflate type compression for iis , lighthttpd , nginx , and even node see: https://github.com/h5bp/server-configs 例如,为iislighthttpdnginx甚至node启用gzip / deflate类型压缩的服务器配置请参阅: https//github.com/h5bp/server-configs

For a very good current implementation of Apache mod_deflate see https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess#L156 有关Apache mod_deflate当前非常好的实现,请参阅https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess#L156

Gzip压缩您的网页和级联样式表,然后将它们发送到客户端浏览器,例如此链接

http://developer.yahoo.com/performance/rules.html#gzip http://developer.yahoo.com/performance/rules.html#gzip

This is the reference if any asks me about my reference loading gzipped files 如果有人询问我的参考加载gzip压缩文件,这是参考

如果您使用的是Lighttpd,则有mod_compress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM