Skip to content

Instantly share code, notes, and snippets.

@tobie
Created September 10, 2012 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobie/3690242 to your computer and use it in GitHub Desktop.
Save tobie/3690242 to your computer and use it in GitHub Desktop.
// Query current usage and availability in Temporary storage:
navigator.temporaryStorage.getInfo(
function (info) {
// Continue to initialize local cache using the obtained
// usage and quota (availability) information.
initializeCache(info);
}, function (error) { log("Got error: ", error);
});
function onError(error) {
// Handle an error.
log("Got error: ", error);
}
function setUpOfflineMode(availableSpace) {
// ...
}
// A function which is to be called when 'offline-mode' is enabled.
function onOfflineEnabled(amountOfSpaceNeeded) {
// First check how much we can use in the Persistent storage.
navigator.persistentStorage.getInfo(
function (info) {
var availableSpace = info.quota - info.usage;
if (availableSpace >= amountOfSpaceNeeded) {
// We're fine; just continue to set up offline mode.
setUpOfflineMode(availableSpace);
return;
}
var requestingQuota = amountOfSpaceNeeded + info.usage;
navigator.persistentStorage.requestQuota(
requestingQuota,
function (grantedQuota) {
setUpOfflineMode(grantedQuota - info.usage);
},
onError);
},
onError);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment