Lesson 4: Working with the offline application HTTP cache CHAPTER 16 607
C. window.requestFileSystem(SIMPLE, 5 * 1024 * 1024, getDirectory, handleError);
D. window.requestFileSystem(TEMPORARY, 5 * 1024 * 1024, getDirectory,
handleError);
- Which of the following allows FileWriter to append data to the end of the file?
A. fileWriter.seek(fileWriter.length);
B. fileWriter.seek(fileWriter.end);
C. fileWriter.moveLast()
D. fileWriter.moveToEnd(); - Which of the following removes a directory that contains existing files?
A. directoryEntry.remove(directoryRemoved, handleError);
B. directoryEntry.removeRecursively(directoryRemoved, handleError);
C. directoryEntry.removeAll(directoryRemoved, handleError);
D. directoryEntry.remove(directoryRemoved, ALL, handleError)
Lesson 4: Working with the offline application HTTP cache
You’ve learned about several features that provide the opportunity to store key/value pairs,
structured data elements, objects, and files. However, none of them alone enables your appli-
cation to operate offline easily. Suppose you have a dynamic web application that gets all its
data from a local IndexedDB instance, but you still need to retrieve items such as CSS files,
JavaScript files, images, and the web page itself. To a degree, you already have this feature
through the browser cache, but it’s always been somewhat unreliable and could not truly
operate without a network connection.
HTML5 delivers an improvement to caching with the application cache, which introduces
the ability to configure how files are cached by including a manifest file. Within this file is a
list of resources to include and exclude from cache and alternate file designations to serve in
some cases.
The application cache works behind the scenes to keep the local cache up to date as the
manifest file is updated. If you lose Internet connection and the browser is taken offline, it will
automatically switch to serve local files.
After this lesson, you will be able to:
■■Understand the offline application HTTP cache.
■■Implement the offline application HTTP cache.
Estimated lesson time: 20 minutes