How can I pre-compress files with mod_deflate in A

2019-01-04 09:35发布

I am serving all content through apache with Content-Encoding: zip but that compresses on the fly. A good amount of my content is static files on the disk. I want to gzip the files beforehand rather than compressing them every time they are requested.

This is something that, I believe, mod_gzip did in Apache 1.x automatically, but just having the file with .gz next to it. That's no longer the case with mod_deflate.

8条回答
一纸荒年 Trace。
2楼-- · 2019-01-04 10:32

I have a lot of big .json files. Most readers are in this situation. The preview answers didn't talk about the returned "Content-type".

I you want the following request return a pre-compressed file with "Content-Type: application/json" transparently, use Multiview with ForceType

http://www.domain.com/(...)/bigfile.json
-> Content-Encoding:gzip, Content-Type: Content-Encoding:gzip

1) files must be rename: "file.ext.ext"

2) Multiview works great with ForceType

In the file system:

// Note there is no bigfile.json
(...)/bigfile.json.gz
(...)/bigfile.json.json

In your apache config:

<Directory (...)>
    AddEncoding gzip .gz
    Options +Multiviews
    <Files *.json.gz>
        ForceType application/json
    </Files>
</Directory>

Short and simple :)

查看更多
干净又极端
3楼-- · 2019-01-04 10:39

You can use mod_cache to proxy local content in memory or on disk. I don't know if this will work as expected with mod_deflate.

查看更多
登录 后发表回答