HOME

TheInfoList



OR:

The cache manifest in HTML5 is a software storage feature which provides the ability to access a
web application A web application (or web app) is application software that is accessed using a web browser. Web applications are delivered on the World Wide Web to users with an active network connection. History In earlier computing models like client-serv ...
even without a network connection. It became part of the
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working to ...
Recommendation on 28 October 2014. As of 2021, this technology is no longer widely available. It was removed from Firefox 85, and disabled by default in Chrome 84 and removed in Chrome 95. Using any of the offline Web application features at this time is highly discouraged and use of service workers is recommended instead.


Background

Web applications consist of web pages that need to be downloaded from a network. For this to happen there must be a network connection. However, there are many instances when users cannot connect to a network due to circumstances beyond their control.
HTML5 HTML5 is a markup language used for structuring and presenting content on the World Wide Web. It is the fifth and final major HTML version that is a World Wide Web Consortium (W3C) recommendation. The current specification is known as the HTML ...
provides the ability to access the web application even without a network connection using the
cache Cache, caching, or caché may refer to: Places United States * Cache, Idaho, an unincorporated community * Cache, Illinois, an unincorporated community * Cache, Oklahoma, a city in Comanche County * Cache, Utah, Cache County, Utah * Cache County ...
manifest. Web applications consist of resources identified by URLs. These can be
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaSc ...
, CSS,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
, images or any other source that is required for a web application to be rendered. Their addresses can be copied into a
manifest file A manifest file in computing is a file containing metadata for a group of accompanying files that are part of a set or coherent unit. For example, the files of a computer program may have a manifest describing the name, version number, license and t ...
, which can be updated regularly by the author of the web application, indicating any new web addresses that are added or deleted. When connecting to a network for the first time, a web browser will read the HTML5 manifest file, download the resources given and store them locally. Then, in the absence of a network connection, the web browser will shift to the local copies instead and render the web application offline.


Basics

In order for the offline applications to work, a cache manifest file must be created by the web developer. If the web application exceeds more than one page then each page must have a manifest attribute that points to the cache manifest. Every page referencing the manifest will be stored locally. The cache manifest file is a text file located in another part of the server. It must be served with content type text/cache-manifest The attribute manifest="" must be added to the ''html'' element in order for the cache manifest file to work. Example: The argument to the manifest attribute is a relative or absolute path to the manifest file. Consider the HTML file given below. The element indicates a file named ''cache.appcache'' will contain the list of resources (i.e., test.js, test.css) needed for this web page to work offline. Common names for this file are cache.manifest and manifest.appcache. Test Testing the manifest file.


Syntax

The ''manifest'' file must start with the line CACHE MANIFEST. Comments start with a #, spaces and blank lines are ignored. Given below is an example of a cache manifest file. Example 1: CACHE MANIFEST /test.css /test.js /test.png This manifest file lists three resources: a CSS file, a JavaScript file and a PNG image. When the above file is loaded, the browser will download the test.css, test.js and test.png files from the root directory in the web server. As a result, whenever one's network is not connected, the resources will be available to them offline. Cache manifests can also use relative paths or even absolute URLs as shown below. Example 2: CACHE MANIFEST /main/features.js /main/settings/index.css http://files/images/scene.jpg http://files/images/world.jpg


File headers

The cache manifest file consists of three section headers. # Explicit section with the header CACHE. # Online whitelist section with the header NETWORK. # Fallback section with the header FALLBACK. Note: Example 1 and Example 2 above, do not indicate any section header and are therefore considered an explicit section by default.


Online whitelist section with the header NETWORK

Example 3: CACHE MANIFEST NETWORK: /checking.cgi CACHE: /test.css /test.js /test.png This example consists of headers. The line, NETWORK: is the start of the "online whitelist" section. The resources listed under this section are never cached and are not available offline. As a result, an error will occur when an attempt is made offline to load the resource. There is a shift to the explicit section by the header CACHE: and the resources (the CSS stylesheet, JavaScript and the image file) can be downloaded and used offline.


Fallback section with the header FALLBACK

The fallback section in a cache manifest file can be used to substitute online resources that cannot be cached or were not cached successfully. Example 4: CACHE MANIFEST FALLBACK: / /offline.html NETWORK: … In Example 4, the fallback section consists of a single line. i.e., ''/ /offline.html''. The single character (''/'') before ‘offline’ will match any URL pattern on one's site. If the browser does not find the page in the appcache, the application will display the page /offline.html.


Event flow

Events are under the ApplicationCache JavaScript object. If the browser visits a web page, has NOT seen the web page before and as a result does not recognize the manifest file, the following events will ensue. * Checking Event - occurs when the browser visits a web page and reads the manifest attribute on the element. * Downloading Event - it will download all the resources given in the manifest file. * Progress Event - contains information of how many files have been downloaded and how many files are left to be downloaded. * Cached Event - occurs once all the files have been downloaded and the offline web application is equipped to be used offline. If the browser has visited the web page before and recognizes the manifest file the following events will ensue. * Noupdate Event - this will take place if the cache manifest has not changed. * Downloading Event - if the cache manifest has changed the resources the files will be downloaded again. * Progress Event - this contains information of how many files have been downloaded and how many files are left to be downloaded. * Updateready Event - after the re-downloading is complete, this event is triggered, indicating that the new offline version is ready to be used. If an error occurs at any instance in the above events, the browser will trigger an error event and stop the process. Given below are a few errors that can occur when re-downloading resources. * Page Not Found ( HTTP error 404) or Page Permanently Gone (HTTP error 410). * Failure to download the HTML page that pointed to the manifest. * The cache manifest changed while the update occurred. * The cache manifest was changed but the browser did not download a resource in the manifest.


See also

*
HTML5 HTML5 is a markup language used for structuring and presenting content on the World Wide Web. It is the fifth and final major HTML version that is a World Wide Web Consortium (W3C) recommendation. The current specification is known as the HTML ...
*
Offline reader An offline reader (sometimes called an offline browser or offline navigator) is computer software that downloads e-mail, newsgroup posts or web pages, making them available when the computer is offline: not connected to a server. Offline readers ...
*
Web cache A Web cache (or HTTP cache) is a system for optimizing the World Wide Web. It is implemented both client-side and server-side. The caching of multimedias and other files can result in less overall delay when browsing the Web. Parts of the sys ...


References

{{Reflist, 30em


External links


Using the application cache - HTML , MDN

HTML5: Offline Application Caching



Alistapart: Application Cache
Cache (computing) HTML5