public
Created

  • Download Gist
example1.js
JavaScript
1 2 3 4 5 6 7 8
// 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);
});
example2.js
JavaScript
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
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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.