You are previewing Building iPhone Apps with HTML, CSS, and JavaScript.

Building iPhone Apps with HTML, CSS, and JavaScript

Cover of Building iPhone Apps with HTML, CSS, and JavaScript by Jonathan Stark Published by O'Reilly Media, Inc.
  1. Building iPhone Apps with HTML, CSS, and JavaScript
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Preface
    1. Who Should Read This Book
    2. What You Need to Use This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
    7. Acknowledgments
  5. 1. Getting Started
    1. Web Apps Versus Native Apps
      1. What Is a Web App?
      2. What Is a Native App?
      3. Pros and Cons
      4. Which Approach Is Right for You?
    2. Web Programming Crash Course
      1. Intro to HTML
      2. Intro to CSS
      3. Intro to JavaScript
  6. 2. Basic iPhone Styling
    1. First Steps
      1. Preparing a Separate iPhone Stylesheet
      2. Controlling the Page Scaling
    2. Adding the iPhone CSS
    3. Adding the iPhone Look and Feel
    4. Adding Basic Behavior with jQuery
    5. What You’ve Learned
  7. 3. Advanced iPhone Styling
    1. Adding a Touch of Ajax
    2. Traffic Cop
    3. Simple Bells and Whistles
    4. Roll Your Own Back Button
    5. Adding an Icon to the Home Screen
    6. Full Screen Mode
      1. Changing the Status Bar
      2. Providing a Custom Startup Graphic
    7. What You’ve Learned
  8. 4. Animation
    1. With a Little Help from Our Friend
    2. Sliding Home
    3. Adding the Dates Panel
    4. Adding the Date Panel
    5. Adding the New Entry Panel
    6. Adding the Settings Panel
    7. Putting It All Together
    8. Customizing jQTouch
    9. What You’ve Learned
  9. 5. Client-Side Data Storage
    1. localStorage and sessionStorage
      1. Saving User Settings to localStorage
      2. Saving the Selected Date to sessionStorage
    2. Client-Side Database
      1. Creating a Database
      2. Inserting Rows
      3. Selecting Rows and Handling Result Sets
      4. Deleting Rows
    3. What You’ve Learned
  10. 6. Going Offline
    1. The Basics of the Offline Application Cache
    2. Online Whitelist and Fallback Options
    3. Creating a Dynamic Manifest File
    4. Debugging
      1. The JavaScript Console
      2. The Application Cache Database
    5. What You’ve Learned
  11. 7. Going Native
    1. Intro to PhoneGap
      1. Using the Screen’s Full Height
      2. Customizing the Title and Icon
      3. Creating a Startup Screen
    2. Installing Your App on the iPhone
    3. Controlling the iPhone with JavaScript
      1. Beep, Vibrate, and Alert
      2. Geolocation
      3. Accelerometer
    4. What You’ve Learned
  12. 8. Submitting Your App to iTunes
    1. Creating an iPhone Distribution Provisioning Profile
    2. Installing the iPhone Distribution Provisioning Profile
    3. Renaming the Project
    4. Prepare the Application Binary
    5. Submit Your App
    6. While You Wait
    7. Further Reading
  13. Index
  14. About the Author
  15. Colophon
  16. Copyright

Chapter 6. Going Offline

There’s a feature of HTML5 called the offline application cache that allows users to run web apps even when they are not connected to the Internet. It works like this: when a user navigates to your web app, the browser downloads and stores all the files it needs to display the page (HTML, CSS, JavaScript, images, etc.). The next time the user navigates to your web app, the browser will recognize the URL and serve the files out of the local application cache instead of pulling them across the network.

The Basics of the Offline Application Cache

The main component of the offline application cache is a cache manifest file that you host on your web server. I’m going to use a simple example to explain the concepts involved, and then I’ll show you how to apply what you’ve learned to the Kilo example we’ve been working on.

A manifest file is just a simple text document that lives on your web server and is sent to the user’s device with a content type of cache-manifest. The manifest contains a list of files that a user’s device must download and save in order to function. Consider a web directory containing the following files:


In this case, index.html is the page that will load into the browser when users visit your application. The other files are referenced from within index.html. To make everything available offline, create a file named demo.manifest in the directory with index.html. Here’s a directory listing ...

The best content for your career. Discover unlimited learning on demand for around $1/day.