LoginSignup
14
13

More than 5 years have passed since last update.

静的ページの更新がキャッシュのせいでできないとき、サーバ側とブラウザ側のどっちを見るべきか

Last updated at Posted at 2017-07-22

いくらページをリロードしても何も起きない

...発端は、HTMLとCSSを勉強していた壮年Kのこんな言葉であった。
なぜ私がせっかく書いたCSSが一切適用されないのだ?

Kはこんな環境で勉強をおこなっている。

  • CentOS6.9
  • VirtualBox最新版(ついさっき更新した)
  • Google Chrome最新版

そもそも

「キャッシュする要因はブラウザ側サーバ側かにあるはずだ」
そう睨んだK。

Kは待つのが嫌いだ。無論、待たされることも。

結論を言おう。Kは以下の手段を試している。

ブラウザキャッシュへの対応策

  • スーパーリロード

Ctrl + F5(Windowsだとこう)

  • 拡張機能「Clear Cache」の導入
  • 開発者用ツールを開いて更新
  • [履歴]からキャッシュを削除

血迷い策

  • Windowsの再起動
  • CentOSの再起動

再起動という大気圏突入

『リロードが反映されないなら、お前ごとリロードしてやる』
Kは言った。

Windows、CentOSともに、再起動後は変更が反映された。

しかし彼はそれ以後、二度とVirtualBoxへと足を踏み入れることはなかった。

...

復活

Kは一念発起した。
何より、問題を解決せぬまま悶々と過ごす日々に、偽りを感じたのだ。

Kはサーバ側にあると思われる原因を追求した。

サーバ側キャッシュへの対応策

  • Apacheの設定ファイルの編集

ApacheとはWebサーバのソフトウエアである。
つまり、それをいじれば万事解決。
そう考えたKはさっそくコンソールを開き始めた。

httpd.confファイルを探せ

CentOSではApacheをhttpdと呼ぶ。
つまりhttpd.confファイルとはApacheの設定ファイルを意味するのだ。

viコマンドで中身を書き換えようとするK。
ところがどこを書き換えたらいいか分からない。

すると、こういう記述を見つけた。

httpd.conf
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.

「つまり、『何かいじりたい項目があれば、ここから下に書け』ってことだな。」
そして、その下に"Directory"タグが見えるはずだ。

焦ってはいけない。
開始タグだけを見て作業は始められない。

「開始タグが用意されているということは、当然閉じタグもあるということだ。」

ついに栄華が手中に

httpd.conf
EnableMMAP Off
EnableSendfile Off

Kは書いた。
書ききったのだ。

『更新完了。』
彼は今日もひとつ勉強したのだった。

~完~

ちなみに

httpd.conf
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html">
    EnableMMAP Off
    EnableSendfile Off

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

httpd.confファイルにさっきの二行を書き加えると
ブラウザでの更新ができるようになりました。

要Apacheの再起動です!!!!!!

14
13
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
14
13