如何通过只具有COM pressed文件服务基于请求的接受编码类型的COM pressed / uncom pressed文件 [英] How to serve compressed/uncompressed files based on request's accepted encoding types by having only compressed files

查看:199
本文介绍了如何通过只具有COM pressed文件服务基于请求的接受编码类型的COM pressed / uncom pressed文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在apache的htdocs下,我想只有COM pressed文件(gzip文件)和基于请求的接受的编码类型,如果启用了gzip编码,我想Apache来服务于COM pressed文件,如果不支持gzip编码,然后我想通过阿帕奇uncom $ p $服务pssing gzip的文件。

In apache htdocs, i want to only have compressed files (gzip file) and based on request's accepted encoding types, if gzip encoding is enabled, I want apache to serve the compressed file and if gzip encoding is not supported, then I want apache to serve by uncompressing the gzip files.

我不想让uncom pressed文件,并使用访问时,因为这将是低效的,并因为默认情况下所有的客户端都支持gzip的编码紧缩对COM preSS。

I don't want to keep uncompressed files and use deflate to compress when accessed as this will be inefficient and as by default all clients support gzip encoding.

通过让两个pssed的COM $ P $和uncom pressed文件(example.js和example.jsgz无论是在htdocs目录),我是能够根据请求的接受编码和RedirectRules使用RedirectCond,使这项工作。但是这需要存储两个文件(COM pressed和正常的)。下面是我和重定向规则中使用的配置。

By having both the compressed and uncompressed files (example.js and example.jsgz both in htdocs directory), I was able to make this work by using RedirectCond on request's accepted encoding and RedirectRules. But this needs two files to be stored (compressed and normal ones). Below is the configuration i used with redirect rules.

<Directory /var/www/app>
AddEncoding gzip .jsgz .cssgz .htmlgz
AddType text/javascript .jsgz
AddType text/css .cssgz
AddType text/html .htmlgz
SetEnv force-no-vary
Header set Cache-Control "private"

RewriteEngine on
# If client accepts compressed files
RewriteCond %{HTTP:Accept-Encoding} gzip
# and if compressed file exists
RewriteCond %{REQUEST_FILENAME}gz -f
# send .htmlgz instead of .html
RewriteRule ^(.+)\.(html|css|js)$ $1.$2gz [L]
</Directory>

我不想因为上面我必须保持每个文件的两个版本做的。

I dont want to do as above as I have to keep both versions of each file.

例如:

app目录里面的htdocs目录

Contents of app directory inside htdocs

ls app/
example.jsgz

有关应用程序的目录服务器端Apache的配置

Server side apache configuration for app directory

在这种情况下,及MultiView选项,我能够服务器example.jsgz当请求文件是example.js作为example.js不是present。而就我的Apache侧配置如下:

In this case with MultiView option, I am able to server example.jsgz when request file is example.js as example.js is not present. And the configuration on my apache side is as below:

<Directory /var/www/htdocs/app>
AddEncoding gzip .jsgz .cssgz .htmlgz
AddType text/javascript .jsgz
AddType text/css .cssgz
AddType text/html .htmlgz
Options +Multiviews
SetEnv force-no-vary
Header set Cache-Control "private"
</Directory>

案例1:

请求头说gzip编码的支持。并且请求的URL是example.js而不是example.jsgz。这是工作和example.jsgz文件送达内容编码为gzip和客户端能够DECOM preSS和使用js文件。

Request headers say gzip encoding is supported. And requested url is example.js and not example.jsgz. This is working and example.jsgz file is served with content encoding as gzip and client is able to decompress and use the js file.

Request URL:http://A.B.C.D/app/example.js
Request Method:GET
Request HTTP headers: 
Accept-Encoding:gzip,deflate,sdch

Response Headers:
Content-Encoding:gzip

案例2:

请求头说,不支持gzip编码。并且请求的URL是example.js而不是example.jsgz。这不是工作作为Apache是​​服务example.jsgz和gzip编码是不支持的客户端失败。

Request headers say gzip encoding is not supported. And requested url is example.js and not example.jsgz. This is not working as apache is serving example.jsgz and client is failing as gzip encoding is not supported.

Request URL:http://A.B.C.D/app/example.js
Request Method:GET
Request HTTP headers: 

Response Headers:
Content-Encoding:gzip

有没有办法来处理案件2当客户不通过只具有htdocs目录COM pressed文件支持gzip编码?

Is there a way to handle case 2 when client doesn't support gzip encoding by just having compressed file in htdocs ?

我看了一下充气和放气选项。也谈MultiViews选项。但我没有在目录级别找到例如,当目录包含COM pressed格式的多种类型的内容(JavaScript,CSS,HTML)(EN gzip的codeD)。

I have read about inflate and deflate options. Also about Multiviews option. But I didn't find example at a directory level when the directory contains multiple types of content (javascript, css, html) in compressed format (gzip encoded).

在此先感谢

推荐答案

看起来这就是你需要的 http://www.innerjoin.org/apache-com$p$pssion/howto.html

Looks like that's what you need http://www.innerjoin.org/apache-compression/howto.html

虽然我没有以任何方式尝试过。

Though I haven't tried it in any way.

另一个选择可能是使用某种语言的脚本运行DECOM pression和应对(PHP,红宝石,perl的...)

Another option might be to use some script language to run decompression and respond (php, ruby, perl...)

至于性能,具有两个版本是因为它不要求任何额外的努力是最好的选择。

As for performance, having both versions is the best option as it doesn't require any extra efforts.

这篇关于如何通过只具有COM pressed文件服务基于请求的接受编码类型的COM pressed / uncom pressed文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆