LoginSignup
1
1

More than 5 years have passed since last update.

jQueryMobileとmobile safariのキャッシュと初期化イベントではまった話

Last updated at Posted at 2015-04-11

mobile safariでは、backボタンで戻るとキャッシュを無効にしても、キャッシュを使ってしまうことがあります。

httpヘッダの設定もダメ。

Cache-Control: no-cache,no-store

headタグの設定もダメ。

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache,no-store">    
<meta http-equiv="Expires" content="-1">

実際のところ、キャッシュされてもいいんです。

ページが表示されたことを補足できればjsでなんとかなるわけです。
jquery mobileでは、ページが表示されると、表示するページ(id=page)にpageshowイベントが発火されることになっています。これが使えると思ったら動きません。

$('#samplepage').on('pageshow', function() {
    // ページが表示されたよ。backでは呼ばれない
});

結局、jqmらしくなく、windowでフックすることで捕捉できました。

$(window).on('pageshow', function() {
    // ページが表示されたよ
});

今回は、jqmのdom管理を無効にしていたからよかったけど、dom管理を有効にしていると厄介なことになるかも。

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