Showing posts with label offline web app. Show all posts
Showing posts with label offline web app. Show all posts

Friday, January 20, 2012

GQueues Mobile: a case for the HTML5 web app

By Cameron Henneke, Founder and Principal Engineer of GQueues

This post is part of Who's at Google I/O, a series of guest blog posts written by developers who are appearing in the Developer Sandbox at Google I/O.


With the proliferation of mobile app stores, the intensity of the native app vs. web app debate in the mobile space continues to increase. While native apps offer tighter phone integration and more features, developers must maintain multiple apps and codebases. Web apps can serve a variety of devices from only one source, but they are limited by current browser technology.

In the Google IO session HTML5 versus Android: Apps or Web for Mobile Development?, Google Developer Advocates Reto Meier and Michael Mahemoff explore the advantages of both strategies. In this post I describe my own experience as an argument that an HTML5 app is a viable and sensible option for online products with limited resources.

Back in 2009 I started developing GQueues, a simple yet powerful task manager that helps people get things done. Built on Google App Engine, GQueues allows users to log in with Gmail and Google Apps accounts, and provides a full set of features including two-way Google Calendar syncing, shared lists, assignments, subtasks, repeating tasks, tagging, and reminders.



While I initially created an “optimized” version of the site for phone browsers, users have been clamoring for a native app ever since its launch two years ago. As the product’s sole developer, with every new feature I add, I consider quite carefully how it will affect maintenance and future development. Creating native apps for iOS, Android, Palm, and Blackberry would not only require a huge initial investment of time, but also dramatically slow down every new subsequent feature added, since each app would need updating. If GQueues were a large company with teams of developers this wouldn’t be as big an issue, although multiple apps still increase complexity and add overhead.

After engaging with users on our discussion forum, I learned that when they asked for a “native app,” what they really wanted was the ability to manage their tasks offline. My challenge was clear: if I could create a fast, intuitive web app with offline support, then I could satisfy users on a wide variety of phones while having only one mobile codebase to maintain as I enhanced the product.

Three months ago I set out to essentially rewrite the entire GQueues product as a mobile web app that utilized a Web SQL database for offline storage and an Application Cache for static resources. The journey was filled with many challenges, to say the least. With current mobile JavaScript libraries still growing to maturity, I found it necessary to create my own custom framework to run the app. Since GQueues data is stored in App Engine’s datastore, which is a schema-less, “noSQL” database, syncing to the mobile SQL database proved quite challenging as well. Essentially this required creating an object relational mapping layer in JavaScript to sit on top of the mobile database and interface with data on App Engine as well as input from the user. As a bonus challenge, current implementations of Web SQL only support asynchronous calls, so architecting the front-end JavaScript code required a high use of callbacks and careful planning around data availability.

During development, my test devices included a Nexus S, iPhone, and iPad. A day before launch I was delighted to find the mobile app worked great on Motorola Xoom and Samsung Galaxy Android tablets, as well as the Blackberry Playbook. This fortuitous discovery reaffirmed my decision to have one codebase serving many devices. Last week I launched the new GQueues Mobile, which so far has been met with very positive reactions from users – even the steadfast “native app” proponents! With a team of developers I surely could have created native apps for several devices, but with my existing constraints I know the HTML5 strategy was the right decision for GQueues. Check out our video and determine for yourself if GQueues Mobile stacks up to a native app.

Wednesday, January 18, 2012

5 google offline productivity apps


We Chromebook and Chrome users love web apps a lot, but we also hate them (occasionally) because most of them only works online.  I have pointed out this being a major drawback of Chromebook and Chrome OS in my previous posts, 9 Reasons why you shouldn’t buy a Chromebook and 5 things Chrome OS should learn from Joli OS.
But things could change.  We gradually see more and more offline web apps emerged in the Chrome Web Store.  In this article I’ll introduce 5 productivity and work related web apps that work without internet connection.  Choices are certainly endless, do let us know your favorite by leaving a comment here!

Offline Google Mail

This is not the first time Google made its services work offline.  In the past it was done through Google Gears.  Earlier this year many of these offline features were pulled down to prepare for a new stage of offline working enabled by HTML5.  This September we begin to see the results and this Offline Google Mail web app is one of them.
Offline GMail
It’s not just a hyperlink to Google Mail.  It can run as a background app in your computer and notify you whenever you receive a new mail.  Every time you run it on Chrome it synchronizes the internet and the storage in your computer so that you read the freshest emails even when internet connection stopped.  It also brings a tablet-like user interface which maximizes the use of screen real estate.
Offline GMail - Background App
This app is far from perfect, though.  A much complained missing feature is access to Contacts when offline.  Contacts are as important as emails for mobile workers.  Some other features on (my) wish list are keyboard shortcuts, caching of attachments, tasks integration…  After all it’s a good start, please work hard Google guys!


Offline Google Calendar

What?  Google Calendar works offline?  Yes, it is a BETA (a.k.a experimental) feature.  Click the top right gear icon in Google Calendar and choose Offline.  You’ll see this pop up window asking you to enable offline mode and warning you about store private data in your computer.
Offline Google Calendar
No, RSVPs you made to events when flying on an airplane would not be synchronized immediately (unless there is satellite internet connection, which I cannot afford).  But once you are online again the online and offline copies would be merged.

Offline Google Docs

Offline Google Docs works in the same way as the Offline Google Calendar.  You can enable the offline mode and get everything downloaded to your computer, then work your head off while on the plane or on a remote beach with no phone reception.
Offline Google Docs
Currently Google Docs can only load Google documents and spreadsheets offline.  And they are READ ONLY.  There is no way you can edit them offline.  And you cannot create new documents.  So what’s this for?  Well, I tried loading my itinerary when travelling abroad recently.  At that time I only needed to read the hotel address and transport directions.  But if you are expecting some editing function, you may need to wait until this technology appears.

Offline Calculator: Scientific Calculator

It’s quite annoying to know that a “computer”, which literally means something capable to compute, cannot be used to do simple calculations offline.  But that’s a common question I heard the most when the concept of Chromebook first came out.
SciCalc - Advanced Scientific Calculator
There are a few offline calculator for Chrome.  The one I’m introducing is Scientific Calculator.  You can use it to do simple maths as well as using 18 functions (e.g. cosine, exponent etc.) and 8 constants (e.g. Pi and e).

Offline Note Taker: Scratchpad

Scratchpad on Chromebook
If you want to take notes while offline, you can’t use Google Docs.  Scratchpad is a convenient tool you should try because it can sync notes back to Google Docs.  You can mark down things (formatting and bullet points supported) offline and have them loaded to the cloud when internet is available.  On Chromebook it appears as a pop up panels just as some other system notifications.

Summary

After writing this short blog post, I found great potential to write more because there are so many useful offline web apps out there.  I’ll continue writing on this topic to make it a series of offline productivity web app reviews.  Stay tuned!

5 offline productivity apps


In Part 1 of my 5 offline productivity apps series, I introduced chrome web apps for email, calendar, documents, note pad and calculators that could be used offline.  This time, I’ll introduce more work-related productivity apps.

MindMapr: Offline Mindmapping Web App

MindMapr
MindMapr is a web app that allows users to create mind maps.  Since it is developed with HTML5 technology, no external plug-ins such as Flash is required.  The user control is simple and intuitive.  Just drag and drop to create and move new nodes and edit them.  Mindmaps could be stored in the browser for later use.  (According to the developer, saving files to desktop computer is not yet implemented)
Watch this video to know how simple it is:
https://www.youtube.com/watch?v=9rB5K1HW_GU
Web Store: https://chrome.google.com/webstore/detail/njkigggmlihigheckmmebgogbgdmllpo

Speech Recognizer

This web app is interesting, yet very useful.  Since version 11 Chrome has a speech recognition function that translate your talk into texts.  This app uses the built-in voice recognition engine in Chrome to read your speech and convert into texts for you.  If you have a long passage to write but cannot type fast, this is what you need.  The app developer has created a Chrome extension, Voice In, which does the same thing, for easy input of text fields on any web site.
Speech Recognizer

Web Store: https://chrome.google.com/webstore/detail/aomjekmpappghadlogpigifkghlmebjk

SpringPad: Save, Organize and Read

I used to be a heavy Evernote user but since a few months ago I have changed to Springpad.  It has a true Chrome web app (unlike the Evernote web app which is a shortcut only).  Now Springpad Chrome web app can be used offline in Chrome browser, which is a great news to people who often clips web pages, make notes and create lists.
Springpad Chrome Offline
Web Store: https://chrome.google.com/webstore/detail/fkmopoamfjnmppabeaphohombnjcjgla

Converter: Conversion Between Units

I used to keep an excel spreadsheet in my desktop computer for unit conversion even when I’m offline.  If I only have Chromebook in hand, I’ll use this Converter web app to do so.  I like it’s simple user interface and that it does not contain advertisements (which are quite common for other free apps).
Converter Chrome Web App
Web Store: https://chrome.google.com/webstore/detail/gncebhdkjgopkmaklokjadihihfakeoi

Remember the Milk:  Never Forget Your To-do

I think many people heard of RTM before.  I’m a daily user of it, even in the office I use RTM instead of the built-in task manager in MS Outlook.  The best thing about are keyboard shortcuts.  You can quickly add and amend tasks by using the mouse.  For example, click on a task and press “R” to amend the description and “D” to change due day.  It has apps for smartphones so that you can carry your to-do on the go and update wherever you are.  It does not have built-in support for GTD or other management systems, but you can easily implement your own by using tags.
Remember The Milk
Web Store: https://chrome.google.com/webstore/detail/chdiaibgndcpagmnpkjoelgfkommjbni

How to create offline HTML5 web apps in 5 easy steps



Among all cool new features introduced by HTML5, the possibility of caching web pages for offline use is definitely one of my favorites. Today, I’m glad to show you how you can create a page that will be available for offline browsing.


Getting started

1 – Add HTML5 doctype

The first thing to do is create a valid HTML5 document. The HTML5 doctype is easier to remember than ones used for xhtml:
<!DOCTYPE html>
<html>
  ...
Create a file named index.html, or get the example files from my CSS3 media queries article to use as a basis for this tutorial.
In case you need it, the full HTML5 specs are available on the W3C website.

2 – Add .htaccess support

The file we’re going to create to cache our web page is called a manifest file. Before creating it, we first have to add a directive to the .htaccess file (assuming your server is Apache).
Open the .htaccess file, which is located on your website root, and add the following code:
AddType text/cache-manifest .manifest
This directive makes sure that every .manifest file is served as text/cache-manifest. If the file isn’t, then the whole manifest will have no effect and the page will not be available offline.

3 – Create the manifest file

Now, things are going to be more interesting as we create a manifest file. Create a new file and save it as offline.manifest. Then, paste the following code in it. I’ll explain it later.
CACHE MANIFEST
#This is a comment

CACHE
index.html
style.css
image.jpg
image-med.jpg
image-small.jpg
notre-dame.jpg
Right now, you have a perfectly working manifest file. The way it works is very simple: After the CACHE declaration, you have to list each files you want to make available offline. That’s enough for caching a simple web page like the one from my example, but HTML5 caching has other interesting possibilities.
For example, consider the following manifest file:
CACHE MANIFEST
#This is a comment

CACHE
index.html
style.css

NETWORK:
search.php
login.php

FALLBACK:
/api offline.html
Like in the example manifest file, we have a CACHE declaration that caches index.html and style.css. But we also have the NETWORK declaration, which is used to specify files that shouldn’t be cached, such as a login page.
The last declaration is FALLBACK. This declaration allows you to redirect the user to a particular file (in this example, offline.html) if a resource (/api) isn’t available offline.

4 – Link your manifest file to the html document

Now, both your manifest file and your main html document are ready. The only thing you still have to do is to link the manifest file to the html document.
Doing this is easy: simply add the manifest attribute to the html element as shown below:
<html manifest="/offline.manifest">

5 – Test it

Once done, you’re ready to go. If you visit your index.html file with Firefox 3.5+, you should see a banner like this one:

Other browser I’ve tested (Chrome, Safari, Android and iPhone) do not warn about the file caching, and the file is automatically cached.
Below you’ll find the browser compatibility of this technique: As usual Internet Explorer does not support it.
  • IE: No support
  • Firefox: 3.5+
  • Safari: 4.0+
  • Chrome: 5.0+
  • Opera: 10.6+
  • iPhone: 2.1+
  • Android: 2.0+

Creating HTML5 Offline Web Applications with ASP.NET


The goal of this blog entry is to describe how you can create HTML5 Offline Web Applications when building ASP.NET web applications. I describe the method that I used to create an offline Web application when building the JavaScript Reference application.
You can read about the HTML5 Offline Web Application standard by visiting the following links:
Currently, the HTML5 Offline Web Applications feature works with all modern browsers with one important exception. You can use Offline Web Applications with Firefox, Chrome, and Safari (including iPhone Safari). Unfortunately, however, Internet Explorer does not support Offline Web Applications (not even IE 9).

Why Build an HTML5 Offline Web Application?

The official reason to build an Offline Web Application is so that you do not need to be connected to the Internet to use it. For example, you can use the JavaScript Reference Application when flying in an airplane, riding a subway, or hiding in a cave in Borneo.
The JavaScript Reference Application works great on my iPhone even when I am completely disconnected from any network. The following screenshot shows the JavaScript Reference Application running on my iPhone when airplane mode is enabled (notice the little orange airplane):
image

Admittedly, it is becoming increasingly difficult to find locations where you can’t get Internet access.
A second, and possibly better, reason to create Offline Web Applications is speed. An Offline Web Application must be downloaded only once. After it gets downloaded, all of the files required by your Web application (HTML, CSS, JavaScript, Image) are stored persistently on your computer.
Think of Offline Web Applications as providing you with a super browser cache. Normally, when you cache files in a browser, the files are cached on a file-by-file basis. For each HTML, CSS, image, or JavaScript file, you specify how long the file should remain in the cache by setting cache headers.
Unlike the normal browser caching mechanism, the HTML5 Offline Web Application cache is used to specify a caching policy for an entire set of files. You use a manifest file to list the files that you want to cache and these files are cached until the manifest is changed.
Another advantage of using the HTML5 offline cache is that the HTML5 standard supports several JavaScript events and methods related to the offline cache. For example, you can be notified in your JavaScript code whenever the offline application has been updated. You can use JavaScript methods, such as the ApplicationCache.update() method, to update the cache programmatically.

Creating the Manifest File

The HTML5 Offline Cache uses a manifest file to determine the files that get cached. Here’s what the manifest file looks like for the JavaScript Reference application:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
CACHE MANIFEST
# v30
Default.aspx
# Standard Script Libraries
Scripts/jquery-1.4.4.min.js
Scripts/jquery-ui-1.8.7.custom.min.js
Scripts/jquery.tmpl.min.js
Scripts/json2.js
# App Scripts
App_Scripts/combine.js
App_Scripts/combine.debug.js
# Content (CSS & images)
Content/default.css
Content/logo.png
Content/ui-lightness/jquery-ui-1.8.7.custom.css
Content/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png
Content/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png
Content/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png
Content/ui-lightness/images/ui-icons_222222_256x240.png
Content/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png
Content/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png
Content/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png
Content/ui-lightness/images/ui-icons_ffffff_256x240.png
Content/ui-lightness/images/ui-icons_ef8c08_256x240.png
Content/browsers/c8.png
Content/browsers/es3.png
Content/browsers/es5.png
Content/browsers/ff3_6.png
Content/browsers/ie8.png
Content/browsers/ie9.png
Content/browsers/sf5.png
NETWORK:
Services/EntryService.svc
http://superexpert.com/resources/JavaScriptReference/
A Cache Manifest file always starts with the line of text Cache Manifest. In the manifest above, all of the CSS, image, and JavaScript files required by the JavaScript Reference application are listed. For example, the Default.aspx ASP.NET page, jQuery library, JQuery UI library, and several images are listed.
Notice that you can add comments to a manifest by starting a line with the hash character (#). I use comments in the manifest above to group JavaScript and image files.
Finally, notice that there is a NETWORK: section of the manifest. You list any file that you do not want to cache (any file that requires network access) in this section. In the manifest above, the NETWORK: section includes the URL for a WCF Service named EntryService.svc. This service is called to get the JavaScript entries displayed by the JavaScript Reference.
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.
If you make changes to files in the manifest (for example, modify a JavaScript file) then you need to make a change in the manifest file in order for the new version of the file to be downloaded. The standard way of updating a manifest file is to include a comment with a version number. The manifest above includes a # v30 comment. If you make a change to a file then you need to modify the comment to be # v31 in order for the new file to be downloaded.

When Are Updated Files Downloaded?

When you make changes to a manifest, the changes are not reflected the very next time you open the offline application in your web browser. Your web browser will download the updated files in the background.
This can be very confusing when you are working with JavaScript files. If you make a change to a JavaScript file, and you have cached the application offline, then the changes to the JavaScript file won’t appear when you reload the application.
The HTML5 standard includes new JavaScript events and methods that you can use to track changes and make changes to the Application Cache. You can use the ApplicationCache.update() method to initiate an update to the application cache and you can use the ApplicationCache.swapCache() method to switch to the latest version of a cached application.
My heartfelt recommendation is that you do not enable your application for offline storage until after you finish writing your application code. Otherwise, debugging the application can become a very confusing experience.

Offline Web Applications versus Local Storage

Be careful to not confuse the HTML5 Offline Web Application feature and HTML5 Local Storage (aka DOM storage) feature. The JavaScript Reference Application uses both features.
HTML5 Local Storage enables you to store key/value pairs persistently. Think of Local Storage as a super cookie. I describe how the JavaScript Reference Application uses Local Storage to store the database of JavaScript entries in a separate blog entry.
Offline Web Applications enable you to store static files persistently. Think of Offline Web Applications as a super cache.

Creating a Manifest File in an ASP.NET Application

A manifest file must be served with the MIME type text/cache-manifest. In order to serve the JavaScript Reference manifest with the proper MIME type, I added two files to the JavaScript Reference Application project:
  • Manifest.txt – This text file contains the actual manifest file.
  • Manifest.ashx – This generic handler sends the Manifest.txt file with the MIME type text/cache-manifest.
Here’s the code for the generic handler:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System.Web;
namespace JavaScriptReference {
    public class Manifest : IHttpHandler {
        public void ProcessRequest(HttpContext context) {
            context.Response.ContentType = "text/cache-manifest";
            context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
        }
        public bool IsReusable {
            get {
                return false;
            }
        }
    }
}
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.

Seeing the Offline Web Application in Action

The experience of using an HTML5 Web Application is different with different browsers. When you first open the JavaScript Reference application with Firefox, you get the following warning:
image
Notice that you are provided with the choice of whether you want to use the application offline or not. Browsers other than Firefox, such as Chrome and Safari, do not provide you with this choice. Chrome and Safari will create an offline cache automatically.
If you click the Allow button then Firefox will download all of the files listed in the manifest. You can view the files contained in the Firefox offline application cache by typing about:cache in the Firefox address bar:
image
You can view the actual items being cached by clicking the List Cache Entries link:
image
The Offline Web Application experience is different in the case of Google Chrome. You can view the entries in the offline cache by opening the Developer Tools (hit Shift+CTRL+I), selecting the Storage tab, and selecting Application Cache:
image
Notice that you view the status of the Application Cache. In the screen shot above, the status is UNCACHED which means that the files listed in the manifest have not been downloaded and cached yet. The different possible values for the status are included in the HTML5 Offline Web Application standard:
  • UNCACHED – The Application Cache has not been initialized.
  • IDLE – The Application Cache is not currently being updated.
  • CHECKING – The Application Cache is being fetched and checked for updates.
  • DOWNLOADING – The files in the Application Cache are being updated.
  • UPDATEREADY – There is a new version of the Application.
  • OBSOLETE – The contents of the Application Cache are obsolete.

Summary

In this blog entry, I provided a description of how you can use the HTML5 Offline Web Application feature in the context of an ASP.NET application. I described how this feature is used with the JavaScript Reference Application to store the entire application on a user’s computer.
By taking advantage of this new feature of the HTML5 standard, you can improve the performance of your ASP.NET web applications by requiring users of your web application to download your application once and only once. Furthermore, you can enable users to take advantage of your applications anywhere -- regardless of whether or not they are connected to the Internet.


If you liked this blog post then please Subscribe to this blog or Kick It for DotNetKicks.      
Subscribe to RSS Feed Follow me on Twitter!