Skip to content

A responsive web application template that uses Application Cache and Local Storage.

License

Notifications You must be signed in to change notification settings

fatcop/offline-app-template

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTML5 Offline App template

TL;DR:

HTML5 Offline App template (demo here) is a responsive web application template that uses Application Cache and Local Storage.

Overview:

What is the minimum amount of code necessary to build a mobile web application that:

  • Can collect user data whilst offline,
  • Automatically post any collected data once online,
  • Responsively adapt to any device it is viewed upon
    ...using only HTML, CSS and javascript?

This small HTML5 web app is an attempt to answer this question and provide a base for more complex apps.

Nothing here is new or original. The following resources were used in it's construction:

But each on it's own wasn't particularly compelling. It was only after combining them that something useful began to emerge.

Online demo:

HTML5 Offline App template Demo
http://bit.ly/QAr7Aa

Install/View:

  • Download and copy these files to some sub-folder of your web server. Browse to ./example1.html
  • Alternatively, simply view the app here.

Details:

  • Because the html header tag contains the string manifest="example1.manifest", complying browsers will cache the resources listed in example1.manifest.
  • This means that subsequent refreshes of the page will NOT result in the resources listed being re-fetched from the server, UNLESS example1.manifest is modified OR the offline cache is manually cleared.
  • Hence the app can be used in situations where there is no connection to the server.
  • Try it and see: disconnect from the internet and refresh the page.
  • Also, reconnect to the internet, modify some copy on the page, browse and click "Check for updates". This forces the app to update it's cache, and refresh the page, but only if example1.manifest had been modified first.
  • "Add a record" adds an item to records in LocalStorage. If the app is online then the entire contents of records will also be uploaded. (I'll let you provide the actual upload code!)
  • If the app is offline then no upload is performed. However, upon detection of being online, the app will fetch records from LocalStorage and perform the upload. This is done in the online event handler in example.js. Try it and see!
  • Messages are logged to the right hand panel to make the underlying process clearer.

Successfully tested on:

  • Chrome (v.23) on MacOS
  • Safari on iPad (iOS v.6.0)
  • Android (v2.2 and v.4) browser

Issues/problems testing on:

  • Android (v.2.2) native browser: The cache doesn't seem to be getting created, though the navigator.onLine / navigator.offLine functionality appears to be OK
    UPDATE - this was fixed by adding an .htaccess file containing "AddType text/cache-manifest manifest" to the app folder.

TODO list:

The following concepts and resources were found to be useful:

About

A responsive web application template that uses Application Cache and Local Storage.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%