W3 Total Cache
「W3 Total Cache」は、Wordpressで作成したブログのキャッシュコントロールやMinify(Page,CSSスタイル、Javascript)といったプログラムの最小化とブラウザ側のキャッシュのチューニングを総合的におこなってくれるプラグインです。その他にWordpressのMySQLデータベースのチューニングやCDN(Contents Delivery Network)つまりWebコンテンツがユーザーに届くまでのネットワークのチューニングもおこなえますが、やや高度な作業となりますので、Page Cache/Minify/Browser Cacheの3つについて設定をしていきます。
説明に使用した画面のWordpressやプラグインのバージョンによって変わります。説明に使用したバージョンは以下のとおり
- wordpress バージョン4.0
- W3 Total Control プラグイン バージョン0.9.4
前提条件
「W3 Total Cache」を使用するには、サーバーのアパッチのモジュールとして以下のものが必要です。- mod_rewrite(必須)
- mod_mime
- mod_headers
- mod_deflate
- mod_expires
インストール
「W3 Total Cache」をインストールするには、wordpressの管理画面から[プラグイン]>[新規追加]と進み、検索窓に”W3 Total Cache”と入力し、プラグインが表示されたらインストールを実行します。準備作業
「W3 Total Cache」の設定をおこなう前に以下の2つの準備作業をおこなってください。 コンフィグファイルに定義を追加 wordpressのルートにあるwp-config.phpの最後に以下を追加define('WP_CACHE', true); // Added by W3 Total Cacheキャッシュフォルダーを新規作成し、書き込み可能(パーミッション:755)とします。 /wp-content/cache
W3 Total Cacheの設定
プラグインを有効化した後、以下の設定(General/詳細)をおこないます。 設定をおこなうには、wordpressの管理画面の[設定]の下に[Performance]が表示されていますので、ここからおこないます。General Setting
Perfermance>General Settingでは、以下の設定をします。 前述したとおり、Page Cache/Minify/Web CacheingのみEnableをONとします。メイン | サブ | 項目 | ON/OFF |
---|---|---|---|
General Settings | General | Toggle all caching types on or off (at once) | OFF |
Page Cache | Enable | ON | |
MInify | Enable | ON(※1) | |
Minify mode | (auto) | ||
Database Cache | Enable | OFF | |
Object Cache | Enable | OFF | |
Brawser Cache | Enable | ON | |
CDN | Enable | OFF | |
Reverse Proxy | Enable vamish cache purging | OFF | |
CloudFlare | Enable | OFF |
※1:CloudFlareサービスでMinifyを使用中である場合、ONに出来ない事に注意。
エラーメッセージ:Minify via disk is currently disabled.
詳細(個別)
個別の設定が以下のように設定してください。メイン | サブ | 項目 | ON/OFF |
---|---|---|---|
Page Cache | General | Don’t cache pages for logged in users | ON |
Cache home page | ON | ||
Cache feeds: site, categories, tags, comments | ON | ||
Cache URIs with query string variables | OFF | ||
Cache 404 (not found) pages | ON | ||
Cache Preload | ON | ||
Minify | General | Rewrite URL structure | ON |
Automatically upload modified files | OFF | ||
HTML Minify settings | Enable | ON | |
Inline CSS minification | ON | ||
Inline JS minification | ON | ||
Don’t minify feeds | OFF | ||
Line break removal | ON | ||
JS minify settings | Enable | ON | |
Combine only after <head> | OFF | ||
Combine only after <body> | OFF | ||
Combine only before </body> | OFF | ||
Comment removal | ON | ||
Line break removal | ON | ||
CSS minify settings | Enable | ON | |
Combine only | ON | ||
Comment removal | OFF | ||
Line break removal | ON | ||
Brawser Cache | General | Set expires header | ON |
Set cache control header | ON | ||
Set entity tag (eTag) | OFF | ||
Set W3 Total Cache header | ON | ||
Enable HTTP (gzip) compression | ON | ||
Do not process 404 errors for static objects with WordPress | OFF | ||
Cascading Style Sheets & JavaScript | Set expires header | ON | |
Set cache control header | ON | ||
Set entity tag (eTag) | OFF | ||
Set W3 Total Cache header | ON | ||
Enable HTTP (gzip) compression | ON | ||
HTML | Set expires header | ON | |
Set cache control header | ON | ||
Set entity tag (eTag) | OFF | ||
Set W3 Total Cache header | ON | ||
Enable HTTP (gzip) compression | ON | ||
Media & Other Files | Set expires header | ON | |
Set cache control header | ON | ||
Set entity tag (eTag) | OFF | ||
Set W3 Total Cache header | ON | ||
Enable HTTP (gzip) compression | ON |
ここで設定した項目は、エクスポートできます。
Perfermance>Genaral Settings>Import / Export Settingsからおこないます。
Rejected User Agentsの設定
Perfermance>Minify>AdvacedにあるRejected User Agentsは、Page Cache を無効にする User-Agent を指定する項目で、ディフォルトでは空欄になってます。Page Cacheを使用すると著しくスピードが落ちるような場合に、User Agent毎に設定しないようにするものです。 通常は、以下のようなUser Agentを設定すると良いでしょう。acer s100 android archos5 bada blackberry9500 blackberry9530 blackberry9550 blackberry 9800 cupcake docomo ht-03a dream froyo googlebot-mobile htc hero htc magic htc_dream htc_magic iemobile/7.0 incognito ipad iphone ipod kindle lg-gw620 liquid build maemo mot-mb200 mot-mb300 nexus one opera mini s8000 samsung-s8000 series60.*webkit series60/5.0 sonyericssone10 sonyericssonu20 sonyericssonx10 t-mobile mytouch 3g t-mobile opal tattoo webmate webos
.htaccessファイルの設定
上記の設定が終了しても、もう一つ設定が残ってます、これは、.htaccessファイルの設定です。 これも、簡単でPerfermance>installからコピペするだけです。 [Perfermance]>[install]で表示された画面中程にある、ルート用の.htaccessファイルの中身をコピーしてださい。 その他に2つほどありますが、こちらはキャッシュが作られる場合に自動的に作成されます。W3TotalCacheから個別にJavascriptの高速化を除外する方法!
・script文の先頭の項目に以下を設定する
<script data-cfasync=”false” src=”…
参考サイト
W3 Total Casheの設定は以下が詳しいです。参考にどうぞ
参考:blog.xeres.jp