Template-Plugin-AddTimeというのをつくった

Posted on 1月 6, 2009
Filed Under cache, coderepos, perl |

codereposに置きました
Template::Plugin::AddTime - TT filter plugin to add file modified time

# 正直あまり自信はないのですが

jsとかcssとか、あまり変化しないのでブラウザにしっかりキャッシュしてほしいけど、
ファイルを更新した時には再読み込みしてほしいって時に、

expiresヘッダをつけないと、ブラウザの実装によってリクエストが来たり来なかったりして
cssを更新したのに読み込まないクライアントは表示が崩れたりします。

なのでexpiresヘッダをつけてしっかりブラウザにキャッシュして欲しいって時に、
ファイルの更新時刻をくっつけたりバージョン番号をくっつけたりすることがあります。

これはファイルの更新時刻をくっつけるためのTT Filterプラグインです。

こんなふうに使います。


# or with a base path
[% USE AddTime(’tmpl/static’) -%]
[% ‘/js/prototype\.js’ | addtime -%]

# adds modified time of tmpl/static/js/prototype\.js
/js/prototype\.js\?1231163490

こうしておいて、lighttpdの設定で
expire.url = (
“/js/” => “access 1 years”,
)

とかってすれば
Expires: Fri, 01 Jan 2010 00:42:29 GMT
Cache-Control: max-age=31104000

こんなヘッダがくっついてくる。

svnでソース管理してる時には ~/.subversion/config
にこう書いておくと
[miscellany]
### Set use-commit-times to make checkout/update/switch/revert
### put last-committed timestamps on every file touched.
# use-commit-times = yes
use-commit-times = yes

ファイルの更新時刻がコミットの時刻になるので便利だったりする時もあります。

?をつけるとキャッシュが利かない時があるって
キャッシュの上手な使い方

こちらにありましたがちょいちょい見た感じそのケースが見つからなかったので、?使っちゃっています。
? 使わなかったら
prototype_1231163490.js みたいにして prototype.js にlighttpdでrewriteするようにするのがいいのかなぁ

Comments

2 Responses to “Template-Plugin-AddTimeというのをつくった”

  1. Gangster86 on 10月 23rd, 2009 1:54

    IV regressions use log population and log area as instruments. ,

  2. Merlin59 on 10月 23rd, 2009 22:54

    As with most philosophical discussions, each show usually provides some factual information about the topic, as well as methods and points of view that are helpful in thinking about the topic. ,

Leave a Reply