9
9

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.

nginxで動いているサイトをApplication Cacheに対応させる手順

Posted at

結構前の記事だけど、ここを参考にさせてもらった。
http://tenderfeel.xsrv.jp/html-xhtml/html5-html-xhtml/1172/

1. .appcacheを作成

どのファイルをキャッシュするのか?といった情報を記載したマニフェストファイルを.appcacheという拡張子で作成する。

例えばこんな感じ。詳しくは上の参考サイト等を参照。

hoge.appcache

CACHE MANIFEST
# バージョンとか更新日時とかここに。

## Cache Files
CACHE:
js/xxx.js
css/xxx.css
img/xxx.png

## Network Files
NETWORK:
*

置く場所はどこでもいいっぽい。まぁ、特別な理由がなければDocumentRootで良いと思う。

2. htmlタグにmanifest属性を追加

キャッシュ対象とするページのhtml(index.htmlとする)をこう。

index.html
<!DOCTYPE html>

- <html lang="ja">
+ <html lang="ja" manifest="hoge.appcache">

	<!-- 省略 -->

</html>

3. nginxのMIMEタイプの設定を変更

/etc/nginx/mime.typeに、appcacheについて追記。

/etc/nginx/mime.type

types {
	(省略)
	text/cache-manifest		appcache;
}

最後に再起動。

# /etc/init.d/nginx restart

以上。とりあえず導入するだけならこれでできるけど、キャッシュの更新をどうするかとかちゃんと考えておかないと危険。


Blog URL : http://www.utano.jp/ (Syntax Error.)

9
9
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
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?