Offline Web Apps

Webapps that are possible to run offline

Web apps in traditional browsers



Old style offline web applications.

The manifest makes it possible to user web apps also without network connectivity. It is also possible to store data locally in the browser. Both for a session and between sessions.

Web apps in Firefox OS



The Firefox browser will support offline web apps in the future. Is is currently available in the beta version of Firefox. Here I'll do a small test of the API. This will also be the way apps are installed in Firefox OS which is a new OS for mobile devices.

A Manifest is needed in order to publish the app on Firefox OS Market.

The manifest must be hosted from the same domain as your website, and must be served with a Content-Type of application/x-web-app-manifest+json`

Small Offline Web App Example:

    <title>Offline webapp</title>

    <!-- Bootstrap -->
    <link href="" rel="stylesheet">

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src=""></script>



    <div class="container">

      <!-- The menu used to show different templates -->
     <div id="test1">
        <a href="#route1">#screen1</a> 
        <a href="#route2">#screen2</a> 
        <a href="#route3">#screen3</a>

      <!-- Templates are rendered here -->
      <div id="ui">

    </div> <!-- /container -->

    <!-- Show test results -->
    <ul id="results"></ul>

    <!-- Templates -->

    <script type="text/template" id="template1">
      <h3>This is screen 1</h3>

    <script type="text/template" id="template2">
      <h3>This is screen 2</h3>

    <script type="text/template" id="template3">
      <h3>This is screen 3</h3>

    <!-- Scripts at the end for better performance -->

    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>

    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>

    <script type="text/javascript">

    // Make sure the page is loading

    window.onload = function(){

      // Define some functions


        // Check if the web apps has been installed and install otherwise

        this.installApp = function installApp() {

          var request = navigator.mozApps.getSelf();

          request.onsuccess = function() {
            if (request.result) {
              // we're installed
              logDebug('App has already been installed');
            } else {
              // not installed
              logDebug('App has not been installed');

              var request2 = navigator.mozApps.install("");
              request2.onsuccess = function() {
                // great - display a message, or redirect to a launch page
                logDebug('App was successfully installed: Name: ' +;
              request2.onerror = function() {
                // whoops - has details
                logErr('ERROR: Could not install app! Error: ' +;


          request.onerror = function() {
            logError('Error checking installation status: ' + this.error.message);



      // Some general setup

      logging.threshold  = logging.debug;
      logDebug('Loading page...');

      if(checkBrowser() != "firefox") {
        logErr('ERROR: only firefox supports offline webapps! You are running ' + checkBrowser() + '.');
        logErr("Continuing but you'll most likely get a bunch of erorrs!");

      // Install the app

      // Setup routing

      // Screen 1
      crossroads.addRoute('route1', function() { 
        var html = $('#template1').html();
        var output = Plates.bind(html, null, null);
        logDebug('logging static route1...');} 

       // Screen 2
       crossroads.addRoute('route2', function() {
       var html = $('#template2').html();
        var output = Plates.bind(html, null, null);
        logDebug('logging static route2...');} 

     // Screen 3      
      crossroads.addRoute('route3', function() {
        var html = $('#template3').html();
        var output = Plates.bind(html, null, null);
        logDebug('logging static route3...');} 

      // Also log routes that did not match anything (useful for debugging)
        logDebug("A route that wasn't matched:"+request); 

      // Setup hasher

      function parseHash(newHash, oldHash){

      // parse initial hash 

      // parse hash changes

      // start listening for history change

      //update URL fragment generating new history record 

    } // window.onload