Get started with localforage CDN

Apache-2.0 licensed

LocalForage is a lightweight, open-source library for key-value storage using the web indexedDB API.

Tags:
  • indexeddb
  • localstorage
  • storage
  • websql

Stable version

Copied!

How to start using localforage CDN


// Include the localforage library
const LocalForage = require('localforage');
const LocalForageCdn = 'https://cdn.cdnhub.io/localforage/1.10.0/localforage.min.js';

// Load the library asynchronously
return new Promise((resolve) => {
  const script = document.createElement('script');
  script.src = LocalForageCdn;
  script.onload = () => {
    resolve(LocalForage);
  };
  document.head.appendChild(script);
});

// Initialize LocalForage
async function initLocalForage() {
  const LocalForageInstance = await initPromise(LocalForage);
  localStorage.clear(); // Clear local storage for testing
  const localforage = new LocalForageInstance.default();

  // Set data
  await localforage.setItem('name', 'John Doe');
  await localforage.setItem('age', 30);

  // Get data
  const name = await localforage.getItem('name');
  const age = await localforage.getItem('age');

  console.log('Name:', name); // John Doe
  console.log('Age:', age); // 30
}

initLocalForage();
Copied!
Copied!
Copied!
Copied!

All versions