Application cache

from Wikipedia, the free encyclopedia

The application cache is a standard that provides a special browser cache for websites, especially web applications . The standard was introduced with HTML5 and is intended to enable pages to be used offline in a simple manner . In practice, however, there were numerous weaknesses, so that the standard is now considered obsolete .

functionality

The application cache is a memory area in which the web browser stores certain resources that are required by a page so that they are immediately available the next time you visit, even if there is no internet connection at the time. It works in a similar way to the normal browser cache and is used in parallel with it.

The cache manifest determines which resources are to be stored. The manifest also indicates whether missing resources should be downloaded over the internet or if fallback should be used instead.

To use a cache manifest, its URL is noted in the manifest- attribute of the <html>- tag . The first time the page is accessed, the browser will download all resources specified in the manifest and cache them. With each subsequent visit, these resources are no longer loaded via the Internet, but are taken directly from the cache. The browser then checks whether the manifest file has changed in the meantime. If this is the case, it will update the cache, but this new version will only be active the next time you visit the page or after a reload.

There is also a JavaScript interface that the page can use to track the state of the cache using events .

Cache Manifest

The cache manifest is a simple text file with the file extension .appcache and the MIME type text/cache-manifest that begins with the identifier CACHE MANIFEST . Comments are lines that begin with a hash sign ( #). The rest of the file consists of entries of three different types: explicit cache entries (in a section with the heading CACHE:or outside of marked sections), fallback entries (in a section with the heading FALLBACK:), and network entries (in a section with the heading NETWORK:). The sections can appear in any order and also multiple times or not at all.

All URLs listed as explicit cache entries and the entries that are cached implicitly by including the manifest are included in the cache. Fallback entries consist of a URL range and the specification of a fallback URL. If a resource from an area listed there cannot be loaded, the fallback is used instead. Finally, network entries indicate which resources should still be loaded via the Internet when using the application cache. The default behavior is that all resources that are not listed in the manifest automatically fail, even if there is an internet connection. This behavior can, however, be changed via a network entry *as a wildcard or more specific information about these resources.

example

Take a page as an example that allows the user to scroll through several images. These images should not all be visible from the start, but should be dynamically reloaded. A CSS style file style.cssand a JavaScript script script.jsare used for this, as well as the images bild1.jpgup to bild4.jpg.

The HTML file could look like this (if the script is responsible for the entire content):

<!DOCTYPE html>
<html manifest="cache.appcache">
 <head>
  <title>Bilderbuch</title>
  <link rel="stylesheet" href="style.css">
  <script src="script.js"></script>
 </head>
 <body>
 </body>
</html>

The cache file specified in the second line could have the following content:

CACHE MANIFEST
#v1
script.js
style.css
bild1.jpg
bild2.jpg
bild3.jpg
bild4.jpg

The HTML file is cached implicitly because it includes the manifest, plus the CSS and JS files and the four images. These are loaded although they are not yet needed at this point, as they are not referenced directly in the HTML file.

If one of the files is updated, the manifest file must be changed. If the list of files has remained the same, it is a good idea to modify a comment and thus create a new version. The second line in the manifest example is used for this.

safety

Below the address bar a dialog is displayed with: "This website (gabrielecirulli.github.io) now saves more than 0MB of data on your computer for use in offline mode."
Asks in Firefox whether a page ( 2048 ) should use the application cache

The application cache enables users to be tracked in a similar way to cookies . There is also the possibility of consuming a lot of storage space. To prevent malicious sites from taking advantage of this, most browsers ask the user before they create an application cache for a site for the first time. Depending on the browser, there are also different options for removing the cache.

Browser support

All current browsers support Application Cache, Mozilla Firefox from version 3.5, Internet Explorer from version 10, Google Chrome from version 4. In Android there is support in the standard browser from version 2.1.

From version 44, Firefox displays a warning in the browser console when Application Cache is used to alert programmers that the technology is out of date.

Problems

In practice, there were numerous problems with the application cache:

  • If a file changes in the cache, all files must be downloaded again.
  • A sensible use is only possible with a manageable number of resources to be cached. There are approaches of how Application Cache can also be used for Internet offers such as Wikipedia , which have a large number of pages, but of which a single user only uses a few, but the cache would on the one hand consume a lot of storage space and on the other hand would save the user often out of date pages shown.
  • If the cache manifest is cached for too long (in the normal browser cache or even in the application cache itself), an update is impossible. Even if the website programmer notices his mistake later, he has no way of correcting it.
  • If a page provides certain resources in different formats (e.g. videos in different codecs or images in different resolutions for different screen sizes), the browser has to download and cache all formats.

In some cases, programmers therefore switch to other technologies, such as web storage . In response to these problems, the service worker standard was developed, which is, however, much more complex and has not yet been implemented in all browsers. The WHATWG has classified the application cache as deprecated since 2015 . If a page uses both service workers and application cache, modern browsers ignore the application cache.

Individual evidence

  1. a b HTML standard. Offline web applications. WHATWG , accessed on July 25, 2016 .
  2. Using the application cache. Storage location and clearing the offline cache. In: Mozilla Developer Network . Retrieved July 25, 2016 .
  3. Can I Use: Offline web applications. Retrieved July 25, 2016.
  4. Firefox 44 for developers. In: Mozilla Developer Network . Retrieved July 25, 2016 .
  5. Jake Archibald: Application Cache is a Douchebag. In: A List Apart . May 8, 2012, accessed July 25, 2016 .
  6. Offline Web Applications - Dive Into HTML5. In: diveintohtml5.info. Retrieved July 25, 2016 .
  7. ^ Service Workers. Motivational. W3C , accessed July 25, 2016 .
  8. Deprecate <keygen> and appcache. August 28, 2015. Retrieved July 25, 2016 .

Web links