代码之家  ›  专栏  ›  技术社区  ›  ken

gzip、apache、php:我应该知道在成熟的站点中实现什么?

  •  3
  • ken  · 技术社区  · 15 年前

    Apache 2.2.17版 5.3.3菲律宾比索

    目前,我的应用程序不使用gzip,但我希望它使用。但是,我不确定以下几点:

    1. 我知道IE6有问题,没必要再回到这里。
    2. 在Apache(mod_flate)和PHP中实现这一点有哪些好处/缺点?它们产生的结果基本相同吗?我想Apache会更有效率,这是正确的假设吗?
    3. 这个应用程序生成了很多类型的响应:PDF、XML、Zip、XLS、CSV、图像(见下一点),当然还有普通的Ajax类型的内容。
    4. 我已经看到许多示例选择不使用gzip图像,这是为什么?这是因为假设大多数图像已经是压缩格式,还是因为它是二进制数据?我会动态地创建一些图像,静态地为其他图像服务。
    5. 我还通过一个PHP机制传输音频文件(wav,mp3);这里有没有找到?

    基本上,如果您已经在一个成熟的站点上实现了gzip,并且遇到了问题,那么我想知道这些问题是什么,以及您为解决这些问题所做的工作。谢谢!

    2 回复  |  直到 15 年前
        1
  •  5
  •   Alan Geleynse buhbang    15 年前

        2
  •  1
  •   Halil Özgür    15 年前

    # Insert filter
    <FilesMatch "(?i)^.*\.(js|css|html?|php3?|xml|txt)$">
        SetOutputFilter DEFLATE
    </FilesMatch>
    # *.cache.js and *.cache.css files are only checked after 6 month (e.g. jQuery.1.4.2.cache.js)
    <FilesMatch "(?i)^.*\.(cache)\.(js|css)$">
        FileETag None
        ExpiresActive On
        ExpiresDefault "access plus 6 month"
    </FilesMatch>
    #AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript
    
    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    # Don't compress images
    #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary