What is application cache in HTML5?
sobes.tech AI
Answer from AI
HTML5 Application Cache (AppCache) is a mechanism that allowed web applications to work offline by loading resources (HTML, CSS, JS, images) into the browser's local cache.
Main components of AppCache:
-
Manifest File: A text file with the extension
.appcache, which lists the resources needed for offline operation. It is specified in themanifestattribute of the<html>tag.<html manifest="example.appcache"> ... </html> -
Manifest sections:
CACHE MANIFEST: The mandatory first line.CACHE:: List of resources that should be explicitly cached.NETWORK:: Resources that always require network access (e.g., API). By default, everything not inCACHEandFALLBACKrequires network.FALLBACK:: Rules for defining fallback resources in case the main resources are unavailable (e.g., offline page).
-
Lifecycle: AppCache has a complex lifecycle, including loading the manifest, comparing versions, downloading resources, and activating the new cache.
Pros:
- Offline access to the application.
- Faster loading for returning users.
Cons:
- Complexity in cache management and updates ("hanging" cache).
- Less flexible compared to Service Workers.
Current status: AppCache is deprecated and gradually being removed from browsers. For implementing offline functionality and resource caching, it is recommended to use Service Workers.