Offline HTML5 web application is a way to allow users to continue interacting with web application while they are not connected to the Internet.In other words It helps to make you connect to the web application while you are not connected to any network. For example, you can access a web application while flying in an airplane, riding in a subway or roaming in the woods.
Another reason to create offline web application is speed. An offline web application must be downloaded only once. After it gets downloaded, all of the files required by the web application are stored on client's computer persistently.Required Resources to develop Offline HTML5 web application:-
1. Manifest file
2. Handler file for serving with a MIME type.1. Manifest File -
A Cache Manifest file always starts with the line of text Cache Manifest. The first line, CACHE MANIFEST, tells the browser that this is a manifest file.
There are three different sections in a manifest file:
CACHE:- A list of explicit URLs to request and store
FALLBACK:- What to do when an offline user attempts to access an uncached file
NETWORK:- Which resources are available only while online
Each section serves a specific purpose.
Example:- In this example the page will be default.aspx. The scripts used in this page will be Scripts/jquery-1.4.4.min.js
CACHE MANIFEST
# Pages name to be downloaded
Default.aspx
# Standard and App Scripts used in above pages
Scripts/jquery-1.4.4.min.js
NETWORK:
# Resources which will only be used when online
Notice that you can add comments to a manifest by starting a line with the hash character (#).
There are two important things that you need to be aware of when using a manifest file. First, all relative URLs listed in a manifest are resolved relative to the manifest file. The URLs listed in the manifest above are all resolved relative to the root of the application because the manifest file is located in the application root.
Second, whenever you make a change to the manifest file, browsers will download all of the files contained in the manifest (all of them). For example, if you add a new file to the manifest then any browser that supports the Offline Cache standard will detect the change in the manifest and download all of the files listed in the manifest automatically.
2. Handler file for serving with a MIME type
The generic handler sends the Manifest.txt file with the MIME type text/cache-manifest.
To do this work there are several ways. You chose depending on your need like for MVC you can write the handler in an ActionResult. You can also do this in a javascript.
Here I am doing this in a separate page called Manifest.ashx
The main two lines of the code.
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
The Default.aspx file contains a reference to the manifest. The opening HTML tag in the Default.aspx file looks like this
<html xmlns=€http://www.w3.org/1999/xhtml€ manifest=€Manifest.ashx€>
Notice that the HTML tag contains a manifest attribute that points to the Manifest.ashx generic handler. Internet Explorer simply ignores this attribute. Every other modern browser will download the manifest when the Default.aspx page is requested.
So now you are ready to create an Offline HTML5 web application.
Happy Coding
Another reason to create offline web application is speed. An offline web application must be downloaded only once. After it gets downloaded, all of the files required by the web application are stored on client's computer persistently.Required Resources to develop Offline HTML5 web application:-
1. Manifest file
2. Handler file for serving with a MIME type.1. Manifest File -
A Cache Manifest file always starts with the line of text Cache Manifest. The first line, CACHE MANIFEST, tells the browser that this is a manifest file.
There are three different sections in a manifest file:
CACHE:- A list of explicit URLs to request and store
FALLBACK:- What to do when an offline user attempts to access an uncached file
NETWORK:- Which resources are available only while online
Each section serves a specific purpose.
Example:- In this example the page will be default.aspx. The scripts used in this page will be Scripts/jquery-1.4.4.min.js
CACHE MANIFEST
# Pages name to be downloaded
Default.aspx
# Standard and App Scripts used in above pages
Scripts/jquery-1.4.4.min.js
NETWORK:
# Resources which will only be used when online
Notice that you can add comments to a manifest by starting a line with the hash character (#).
There are two important things that you need to be aware of when using a manifest file. First, all relative URLs listed in a manifest are resolved relative to the manifest file. The URLs listed in the manifest above are all resolved relative to the root of the application because the manifest file is located in the application root.
Second, whenever you make a change to the manifest file, browsers will download all of the files contained in the manifest (all of them). For example, if you add a new file to the manifest then any browser that supports the Offline Cache standard will detect the change in the manifest and download all of the files listed in the manifest automatically.
2. Handler file for serving with a MIME type
The generic handler sends the Manifest.txt file with the MIME type text/cache-manifest.
To do this work there are several ways. You chose depending on your need like for MVC you can write the handler in an ActionResult. You can also do this in a javascript.
Here I am doing this in a separate page called Manifest.ashx
The main two lines of the code.
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
The Default.aspx file contains a reference to the manifest. The opening HTML tag in the Default.aspx file looks like this
<html xmlns=€http://www.w3.org/1999/xhtml€ manifest=€Manifest.ashx€>
Notice that the HTML tag contains a manifest attribute that points to the Manifest.ashx generic handler. Internet Explorer simply ignores this attribute. Every other modern browser will download the manifest when the Default.aspx page is requested.
So now you are ready to create an Offline HTML5 web application.
Happy Coding
SHARE