Documentos de Académico
Documentos de Profesional
Documentos de Cultura
de la caché de aplicaciones
By Eric Bidelman
Publicación: junio 18th, 2010
Actualización: octubre 29th, 2013
Comments: 9
Introducción
Cada vez es más importante poder acceder a las aplicaciones web
sin conexión. Es cierto que todos los navegadores tienen
mecanismos de almacenamiento en caché, pero esos sistemas no
son fiables y no siempre funcionan como debieran. HTML5 permite
resolver algunas de las molestias asociadas al trabajo sin conexión
mediante la interfaz ApplicationCache.
<html manifest="example.appcache">
...
</html>
<html manifest="http://www.example.com
/example.mf">
...
</html>
- url: /mystaticdir/(.*\.appcache)
static_files: mystaticdir/\1
mime_type: text/cache-manifest
upload: mystaticdir/(.*\.appcache)
CACHE MANIFEST
# 2010-06-18:v2
CACHE MANIFEST
# 2010-06-18:v3
Estado de la caché
El objeto window.applicationCache permite acceder (mediante
programación) a la caché de aplicación del navegador. Su
propiedad status permite comprobar el estado de la memoria
caché:
switch (appCache.status) {
case appCache.UNCACHED: // UNCACHED == 0
return 'UNCACHED';
break;
case appCache.IDLE: // IDLE == 1
return 'IDLE';
break;
case appCache.CHECKING: // CHECKING == 2
return 'CHECKING';
break;
case appCache.DOWNLOADING: // DOWNLOADING == 3
return 'DOWNLOADING';
break;
case appCache.UPDATEREADY: // UPDATEREADY == 4
return 'UPDATEREADY';
break;
case appCache.OBSOLETE: // OBSOLETE == 5
return 'OBSOLETE';
break;
default:
return 'UKNOWN CACHE STATUS';
break;
};
...
if (appCache.status ==
window.applicationCache.UPDATEREADY) {
appCache.swapCache(); // The fetch was
successful, swap in the new cache.
}
window.applicationCache.addEventListener('updatere
ady', function(e) {
if (window.applicationCache.status ==
window.applicationCache.UPDATEREADY) {
// Browser downloaded a new app cache.
// Swap it in and reload the page to get the
new hotness.
window.applicationCache.swapCache();
if (confirm('A new version of this site is
available. Load it?')) {
window.location.reload();
}
} else {
// Manifest didn't changed. Nothing new to
server.
}
}, false);
}, false);
function handleCacheEvent(e) {
//...
}
function handleCacheError(e) {
alert('Error: Cache failed to update!');
};
Referencias
Especificación del API ApplicationCache