CakePHP3で画像,JS,CSSのキャッシュを無効にする方法。
CakePHP2系ではapp/config/core.phpに
app/config/app.php
の76行目あたり
デバッグモード(debug => trueの設定時)のときのみクエリストリングを付けたい場合 : true
デバッグモード時に限らず、常にクエリストリングを付けたい場合 : 'force'
を設定してやれば良い。
CakePHP2系ではapp/config/core.phpに
Configure::write('Asset.timestamp', 'force'); // または Configure::write('Asset.timestamp', true);と記述すれば良かったが、CakePHP3系では記述方法が変わっていたのでそのまとめ。
Asset.timestamp設定箇所
CakePHP3系ではapp/config/app.php
の76行目あたり
'Asset' => [ // 'timestamp' => true, ],ここのコメントを外して、'force'かtrueを設定してやれば良い。
'force'とtrueの違い
上記で設定する'force'とtrueの違いについて、cakeソース内のコメント文に記述があった。/** * Apply timestamps with the last modified time to static assets (js, css, images). * Will append a querystring parameter containing the time the file was modified. * This is useful for busting browser caches. * * Set to true to apply timestamps when debug is true. Set to 'force' to always * enable timestamping regardless of debug value. */つまり、
デバッグモード(debug => trueの設定時)のときのみクエリストリングを付けたい場合 : true
デバッグモード時に限らず、常にクエリストリングを付けたい場合 : 'force'
を設定してやれば良い。
コメント