One of the HTML5 features I have been exploring lately is HTML5 offline applications. This is a very powerful feature that allows us to still use web applications even when no network is available. I call it airplane mode, because when I fly I don't like to pay for the in flight WiFi, but still do a lot of work. Plus no one can bother me , but that is a side benefit.
<!-- Conditional comment for mobile ie7 http://blogs.msdn.com/b/iemobile/ -->
<!--[if IEMobile 7 ]> <html class="no-js iem7"> <![endif]-->
<!--[if (gt IEMobile 7)|!(IEMobile)]><!-->
To make offline applications work you must include a reference to a cache manifest file. Above is a code snippet modified from the HTML5 Boilerplate project. In this file you direct the browser to store certain resources so they are accessible when the computer is not connected to the server. I am not going to discuss how to create a manifest today, there are plenty of tutorials around the Internet describing how to do this. Today I want to talk about how to make IIS Express serve an offline cache manifest file.
In general web servers only serve a targeted set of file types as a security precaution. As you need to add files you enable the file type to be served. To help the web server know how to serve a particular file type you need to configure it's MIME type. Since IIS Express does not have a handy control panel GUI you have to configure it through a command line utility.
Before adding a MIME type for an offline cache file any request for the file will most likely return a 404.3 status code. This indicates the request is not permitted because the server does not have a configured MIME type yet. There are some instructions offered to add the MIME type using the command line utility. Using those instructions you can apply any sort of MIME type you may need. For this article I am going to focus on HTML5 cache manifest.
First you need to open a command prompt and change to the IIS Express folder, C:\Program Files (x86)\IIS Express for most. Next you need to enter the following line:
appcmd set config /section:staticContent /+[fileExtension='.appcache',mimeType='text/cache-manifest']
The two places you need to change for other MIME types are the fileextension and the mimeType parameters. Here I used '.appcache' as my offline manifest file extension, there is nothing that says that should be the only file extension type, but is fairly common. The manifest MIME type is text/cache-manifest. This tells the browser what type of file it is. By registering this MIME type the web server will include that in the response header each time it is requested.
In my screenshot you can see that it will not allow you to add the same record, so I added a slight variation so you can see a successful response message. After applying the new MIME type you will now be able to serve an HTML5 offline cache manifest file.
If you use ASP.NET MVC or another server-side generating framework, say PHP or Node.js you will need to set the MIME type in the code. Dean Hume has an article you can reference for MVC and HTML5 offline manifest. I am not sure if you need to register an extension less file type in IIS Express at this point, my guess is no. Craig Shoemaker also has a very detailed article about MVC and HTML5 offline manifest available on Code Magazine. I am not sure I would recommend generating an offline cache manifest file because they do not change often and serving static content is faster than generated content.