Open In App

What is the Application Cache and why it is used in HTML5 ?

The task is to learn about the application cache in HTML5. HTML stands for HyperText Markup Language and it is used to design web pages using a markup language. HTML5 is current or we can also say that it’s the 5th version of HTML.

Application Cache in HTML5: The current version of HTML5 introduces application cache, which means that a web application is cached, and accessible without an internet connection. Now we can make an offline web application that will run without an internet connection by just creating a manifest file in our application. 



Syntax:

<html manifest="demo.appcache">

Structure of HTML file: HTML is nothing but just an element tag that comes after the doctype tag in HTML structure. 



 




<!DOCTYPE html>
<html>
  <!-- In this element we will add an attribute
       called manifest attribute-->
  <head>
    <title>Page Title</title>
  </head>
  <body>
    <h2>Welcome To GFG</h2>
    <p>It is a paragraph element</p>
  
  </body>
</html>

Let us understand the concept of application cache with the help of an example.

Approach: 

Example: The name of the main file is “index.html”. First, the main file will execute and when you try to open the linked page the next page will run. After that, you just have to go offline and reload the page. the content of the page will still work fine.




<!DOCTYPE html>
<html manifest="demo.appcache">
  <body>
    Welcome to GeeksForGeeks.
    <p>
      Try opening <a href="index2.html">this page</a>,
      then go offline, and reload the page. The content 
      should still work.
    </p>
  
  </body>
</html>




<!DOCTYPE html>
<html manifest="demo.appcache">
  <body>
    Welcome to GFG, a computer science portal for geeks.
  </body>
</html>

Output: 

Uses of the application cache are:

Supported browsers:


Article Tags :