4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コンテンツの転送速度をアップする(レスポンス圧縮化)

Last updated at Posted at 2016-05-11

WEBサーバでコンテンツの転送速度をアップする方法

WEBサーバにおいて、ドキュメントを返すとき、圧縮して返してあげると回線の負荷軽減やスピードアップにつながる。今回はapacheで実現する。

httpd.conf

「mod_deflate」を使用して実現する。

画像など既に圧縮されているものに関しては圧縮しないように制限をかける。
今回は画像拡張子以外は全て圧縮とした。

もし、特定のMIMEタイプのみ圧縮したい場合は
SetOutputFilter DEFLATE
を外し
AddOutputFilterByType DEFLATE text/plain
上記のようにタイプを指定すること。
複数指定したい場合は半角 区切りで。
AddOutputFilterByType DEFLATE text/html text/plain

圧縮レベルは
Level 9にしてもそこまでサイズが小さくなるわけではないので
CPUへの負担が少ないLevel 1 とした。
DeflateCompressionLevel 1

画像以外の例

httpd.conf
<IfModule deflate_module>
SetOutputFilter DEFLATE

DeflateCompressionLevel 1

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE\s(7|8) !no-gzip !gzip-only-text/html

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|ico)$ no-gzip dont-vary

Header append Vary Accept-Encoding env=!dont-vary
</IfModule>

type指定&画像以外

httpd.conf
<IfModule deflate_module>
    DeflateCompressionLevel 1

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE\s(7|8) !no-gzip !gzip-only-text/html

    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/x-javascript
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|ico)$ no-gzip dont-vary

    Header append Vary Accept-Encoding env=!dont-vary
</IfModule>
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?