HTML5 Application Cache: What It Is & Why Use It
In this article
The HTML5 application cache (often called AppCache) was a browser feature that let websites tell the browser which files to store locally, so the page could load and function even when the user was offline. It was introduced as part of the HTML5 specification and was used for years to create offline web apps. However, it was deprecated in favor of the more flexible Service Worker API, and modern browsers no longer support it. This article explains what AppCache was, how it worked, why developers used it, and why it was eventually replaced.
Background: The Problem AppCache Solved
Before AppCache, web pages required a live internet connection. If you lost connectivity, you saw a browser error page. This was a major limitation for web apps that users might want to access on the go, such as reading a news article on a train or using a task list in a remote area. Developers tried workarounds like storing data in cookies or using browser extensions, but these were limited and inconsistent.
AppCache was proposed as a standard way to let a web page declare which resources (HTML, CSS, JavaScript, images) should be cached locally. The idea was that once cached, the page would load from the local copy, even when offline, and updates could be fetched when the connection returned.
How AppCache Worked: The Manifest File
To use AppCache, a developer created a text file called a cache manifest (usually named app.manifest or cache.manifest). This file listed the files to cache and the files to always fetch from the network. The manifest was referenced from the HTML page with a manifest attribute on the <html> tag:
<html manifest="/app.manifest">
The manifest file had a specific format:
- CACHE MANIFEST – the first line, required.
- CACHE: – section listing files to store locally (e.g.,
index.html,style.css,app.js). - NETWORK: – section listing resources that must be fetched from the network (e.g.,
login.php). - FALLBACK: – section defining fallback pages when a resource is unavailable (e.g.,
/ /offline.html).
When a user visited the page, the browser read the manifest, downloaded the listed files, and stored them. On subsequent visits, the browser used the cached copies. To update the cache, the developer changed the manifest file (even a comment change triggered an update check), and the browser would download the new files in the background.
Why Developers Used AppCache
The primary motivation was offline capability. With AppCache, a web app could be used without an internet connection, which was valuable for:
- Mobile users in areas with poor connectivity.
- Web-based tools for field workers (e.g., inventory tracking).
- Reading content offline, like news articles or documentation.
- Reducing server load by serving cached files.
AppCache also improved performance for repeat visits because files were served from the local disk, reducing load time and bandwidth usage.
Common Problems and Why It Was Deprecated
AppCache had serious design flaws that made it difficult to use correctly. One major issue was that once a file was cached, it was very hard to update. The browser would check the manifest, but if the manifest itself was cached, changes to it might not be detected. Developers often resorted to changing the manifest file's content (like adding a comment) to force an update, but this was unreliable.
Another problem was that AppCache cached everything listed, even if the user never visited that page. This wasted storage. Also, if any single file in the manifest failed to download, the entire cache update failed, leaving the old cache in place.
Because of these issues, the World Wide Web Consortium (W3C) deprecated AppCache in 2014, recommending that developers use Service Workers instead. Service Workers are JavaScript files that run in the background and give developers fine-grained control over caching and network requests. They can intercept requests, cache responses, and handle offline scenarios more elegantly. As of 2024, all major browsers have removed or are in the process of removing AppCache support.
Comparison: AppCache vs. Service Workers
Service Workers are the modern replacement for AppCache. Unlike AppCache's declarative manifest, Service Workers use JavaScript to programmatically control caching. This allows for:
- Dynamic caching strategies (e.g., cache-first, network-first, stale-while-revalidate).
- Per-request control, so you can cache only what's needed.
- Background sync and push notifications.
- Better error handling and update mechanisms.
Service Workers are more complex to implement but offer far more flexibility and reliability. They are now the standard for building offline-first web apps.
How to Choose: When to Use AppCache (Historically)
In the past, AppCache was the only standard way to create offline web apps. Developers chose it when they needed a simple offline solution without writing complex JavaScript. It was suitable for small, static sites that didn't change often. However, given its deprecation, developers today should use Service Workers or a library like Workbox that wraps Service Workers for easier management.
If you are maintaining an old site that still uses AppCache, you should migrate to Service Workers as soon as possible, because browsers are dropping support, and your offline functionality will break.
Safety and Security Considerations
AppCache had security implications. Since it stored files locally, it could potentially be used to serve malicious content if the manifest was compromised. Also, because caching was automatic, sensitive data might be stored on the user's device without their knowledge. Developers had to be careful not to cache pages that contained personal information.
Modern Service Workers also require careful handling of sensitive data, but they offer more control, such as the ability to bypass caching for authenticated requests.
Frequently Asked Questions
Is AppCache still supported in browsers?
No. All major browsers have deprecated and removed AppCache support. Chrome removed it in version 85 (2020), Firefox in version 84 (2020), and Safari in version 13 (2019). Using AppCache today will have no effect.
What is the difference between AppCache and browser cache?
Browser cache is a general-purpose cache that stores HTTP responses based on headers like Cache-Control and Expires. AppCache was a specific mechanism that stored a declared list of files for offline use, independent of HTTP caching rules.
Can I use AppCache for a simple offline page?
No, because it's not supported anymore. For a simple offline page, you can use a Service Worker to cache the page's HTML, CSS, and JS. There are many tutorials available.
What is the manifest attribute in HTML?
The manifest attribute on the <html> element was used to specify the URL of the cache manifest for AppCache. It is now obsolete and ignored by browsers.
Why did AppCache fail?
AppCache failed due to its rigid design, which made updates unreliable, and its tendency to cache too much. It also had a poor security model. The web community recognized these flaws and created Service Workers as a more powerful and flexible replacement.