And that's why I said it's really common to
have a version string in your manifest file, and you
keep updating that version string. This can be quite
a pain, but it isn't too hard. So once we
have an app cache on the user's machine, on
every subsequent load, the resources will be loaded from the
app cache, even when you're online. If it's an
HTML resource with the manifest For example, that master page
we started with. Then we'll start an async update of
that manifest file at the same time. And then continue loading
the rest of the page. Now, if the manifest has been
changed, the browser will update the files in a new application
cache. But remember, it's already loaded the page. It may
be done loading a page by this point since we do
want to be offline first and we want to make sure that
the page gets loaded as quickly as possible. By the time
the manifest file has been downloaded in the background,
the user is probably already off looking at cat
videos out of the application cache. Now, you can
detect when a new cache has been downloaded and there's
new content available. You can listen for an update
ready event on the window application cache object. The
window application cache represents the application cache system. And
you can get things like the status and progress and
tell it specifically to do things like update
the cache or swap the cache out. So
you have a lot of control over the
application cache. This code here checks for an
update ready event, and if there is actually
an update ready, then it'll actually ask the
user, is it okay to reload this. And if so, it swaps the cache out and reloads.
Por eso mencioné que es muy común
tener una cadena de la versión
en el archivo de manifiesto
y seguir actualizándola en cada versión.
Puede ser aburrido,
pero no es muy difícil.
Cuando tengamos la AppCache
en la máquina del usuario,
cada vez que se cargue,
los recursos se cargarán
desde la caché de aplicaciones,
incluso si estamos en línea.
Si es un recurso HTML con el manifiesto,
por ejemplo, la página maestra
con la que empezamos,
haremos una actualización asíncrona
del manifiesto al mismo tiempo.
Y luego cargaremos el resto de la página.
Si el manifiesto cambió,
el navegador actualizará los archivos
en una nueva caché de aplicaciones.
Recuerda que ya cargó la página.
Quizá la está descargando en este punto,
porque queremos estar sin conexión
y cerciorarnos de que se carga
lo más rápidamente posible.
Cuando el manifiesto
esté descargado en segundo plano,
lo más seguro es que el usuario ya
esté mirando sin conexión videos de gatos
procedentes de la caché de aplicaciones.
Puedes detectar si se descargó
una nueva caché
y si hay nuevo contenido disponible
al escuchar el evento 'updateready'
del objeto window.applicationCache.
Este objeto representa el sistema
de la caché de aplicaciones.
Puedes tomar el estado y el progreso
e indicarle que haga una actualización
o un intercambio (swap) de la caché.
Manejamos un gran control
de la caché de aplicaciones.
Este código de aquí comprueba
los eventos 'updateready'
y, si hay una actualización lista,
le preguntará al usuario
si puede volver a cargar.
En ese caso, intercambia la caché
y vuelve a cargar.
manifestのファイルに一般的に
バージョンストリングがあるのはそのためです
このバージョンストリングを更新し続けます
かなり面倒ですがあまり難しくはありません
アプリケーションキャッシュをインストールすれば
すべてロードした後はオンライン時でも
リソースがロードされます
例えば先ほど使用したマスターページのような
manifestつきのHTMLリソースでは
そのmanifestのファイルの非同期アップデートを
同時に始めます
その後ページの残りを引き続きロードします
もしmanifestが変更されていれば
ブラウザは新しいアプリケーションキャッシュの
ファイルに更新します
思い出してください この時点ですでに
ページはロードされているかもしれません
オフラインを第一に構築したためできるだけ速く
ページがロードされるようになっています
manifestのファイルがバックグラウンドで
ダウンロードされた頃には
アプリケーションキャッシュから
猫の動画を見ることができるでしょう
新しいキャッシュがダウンロードされ
新しいコンテンツがあることを検出することができます
window.applicationCacheオブジェクトで
アップデート可能か判定する
イベントリスナーを設定します
window.applicationCacheは
アプリケーションキャッシュシステムを表わします
さらにステータスや進行状況などを得て
キャッシュのアップデートやスワップを行うよう
命じることができます
アプリケーションキャッシュに関しては
いろいろコントロールできます
このコードはアップデートが実行可能かの
イベントをチェックし
アップデートが実行可能なら
リロードするかをユーザに問います
OKならばキャッシュをスワップしリロードします
E é por isso que eu disse que é comum
ter uma versão string
no arquivo manifesto e
manter atualizando a versão string.
Isso pode dar
trabalho, mas não é difícil. Uma vez que
tenhamos um app cache
na máquina do usuário,
em todo carregamento subsequente,
os recursos serão carregados
do app cache, mesmo
quando estiver online. Se for
um recurso HTML com o manifesto,
por exemplo, a página mestre
que começamos. Começamos
uma atualização Async
do arquivo manifesto
ao mesmo tempo. E continue a carregar
o restante da página.
Agora, se o manifesto for
modificado, o navegador atualizará
os arquivos em um novo aplicativo
cache. Mas lembre-se, já carregou a página.
Pode ser feito carregando
a página, visto que
queremos estar offline primeiro
e queremos ter certeza de que
a página seja carregada
o mais rápido possível. No momento
em que o arquivo manifesto
estiver baixado no fundo,
provavelmente o usuário já está
vendo os vídeos
de gatos do aplicativo cache. Você pode
detectar quando um novo cache foi baixado e
um novo conteúdo está disponível.
Pode ouvir "atualização pronta"
na janela do aplicativo cache.
A janela do aplicativo cache representa
o sistema do aplicativo cache.
Você pode conseguir coisas como
a condição e o progresso e
dizer especificamente para
fazer coisas como atualização
do cache ou troca do cache.
Você tem muito controle do
aplicativo cache. Este código aqui verifica
se um evento está pronto
para ser atualizado e se há
uma atualização pronta, e irá perguntar
ao usuário se é possível recarregar.
Se o for, troca o cache e recarrega.