All Projects → oslabs-beta → loQL

oslabs-beta / loQL

Licence: MIT license
loQL is a lightweight, open source npm package that caches API requests with service workers, unlocking performance gains and enabling offline use.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to loQL

Dsw
Dynamic Service Worker - making your offline Progressive Web Apps way easier
Stars: ✭ 277 (+465.31%)
Mutual labels:  service-worker, indexeddb
sfsdb
Simple yet extensible database you already know how to use
Stars: ✭ 36 (-26.53%)
Mutual labels:  caching, indexeddb
Vbox
vue实现的音乐Web App
Stars: ✭ 73 (+48.98%)
Mutual labels:  service-worker, indexeddb
Sw Toolbox
A collection of tools for service workers
Stars: ✭ 3,649 (+7346.94%)
Mutual labels:  caching, service-worker
Offline First
🔌 Everything you need to know to create offline-first web apps.
Stars: ✭ 2,792 (+5597.96%)
Mutual labels:  service-worker, indexeddb
Offline Plugin
Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
Stars: ✭ 4,444 (+8969.39%)
Mutual labels:  caching, service-worker
kvs
Lightweight key-value storage library for Browser, Node.js, and In-Memory.
Stars: ✭ 126 (+157.14%)
Mutual labels:  indexeddb
sw-loader
Yet another service worker loader
Stars: ✭ 19 (-61.22%)
Mutual labels:  service-worker
cms
A general purpose java cms
Stars: ✭ 23 (-53.06%)
Mutual labels:  caching
cachecontrol
Minimal HTTP cache management library in Scala
Stars: ✭ 13 (-73.47%)
Mutual labels:  caching
PHP-File-Cache
Light, simple and standalone PHP in-file caching class
Stars: ✭ 34 (-30.61%)
Mutual labels:  caching
firefighter-demo
🚨 Demo to improve an existing firefighter app by making it queue tasks offline
Stars: ✭ 68 (+38.78%)
Mutual labels:  service-worker
tips
Here is what you need to setup your progressive web app dev environment
Stars: ✭ 14 (-71.43%)
Mutual labels:  service-worker
ember-app-shell
No description or website provided.
Stars: ✭ 23 (-53.06%)
Mutual labels:  service-worker
next-with-workbox
Higher order Next.js config to generate service workers
Stars: ✭ 22 (-55.1%)
Mutual labels:  service-worker
affilicats
🐈 Progressive Web App demo that showcases flaky network resilience measures (📶 or 🚫📶).
Stars: ✭ 65 (+32.65%)
Mutual labels:  service-worker
extension
web scraping extension
Stars: ✭ 28 (-42.86%)
Mutual labels:  indexeddb
magento-meanbee-pwa
Progressive Web App extension for Magento 1
Stars: ✭ 75 (+53.06%)
Mutual labels:  service-worker
performance-dashboard
Magento 2 Performance Dashboard
Stars: ✭ 60 (+22.45%)
Mutual labels:  caching
stupid-rss-reader
⊕ PWA RSS client on Angular 11
Stars: ✭ 43 (-12.24%)
Mutual labels:  service-worker

loQL

A light, modular npm package for performant client-side GraphQL caching with Service Workers and IndexedDB. More detailed information about installing and configuring loQL can be found here.

Installation

Install via npm

npm install loql-cache

Or with Yarn

yarn add loql-cache

The service worker must also be included in your build folder. With webpack:

const path = require('path');

module.exports = {
  entry: {
    bundle: './client/index.js',
    loQL: './node_modules/loql-cache/loQL.js', // Add this line!
  },
  output: {
  path: path.resolve(__dirname, 'public'),
    filename: '[name].js',
    clean: true,
  },
  devServer: {
    static: './client',
  },
};

Register the service worker

import { register } from "loql-cache";
register({ gqlEndpoints: ["https://foo.com"] });

Settings

gqlEndpoints: string[] Required

Enable caching for specific GraphQL endpoint URLs. Network calls from the browser to any URL not listed here will be ignored by the service worker and the response data will not be cached.

useMetrics: boolean Optional

Enable metrics collection.

cacheMethod: string Optional

Desired caching strategy. The loql-cache package supports both "cache-first" and "cache-network" policies.

cacheExpirationLimit: Integer Optional

The interval, in milliseconds, after which cached data is considered stale.

doNotCacheGlobal: string[] Optional

Fields on a GraphQL query that will prevent the query from being cached, no matter the endpoint.

doNotCacheCustom:{ [url]: string[] } Optional

This setting is like doNotCacheGlobal, but can be used on a per-endpoint basis.

Example Configuration

const loQLConfiguration = {
  gqlEndpoints: ['http://localhost:<###>/api/graphql', 'https://<abc>.com/graphql'],
  useMetrics: false,
  cacheExpirationLimit: 20000,
  cacheMethod: 'cache-network',
  doNotCacheGlobal: [],
  doNotCacheCustom: {
     'http://localhost:<###>/api/graphql': ['password'],
     'https://<abc>.com/graphql': ['account', 'real_time_data'];
  }
};

register(loqlConfiguration);

Features

  • Enables offline use: IndexedDB storage provides high-capacity and persistent storage, while keeping reads/writes asynchronous
  • Minimum-dependency: No server-side component, avoid the use of large libraries
  • Cache validation: Keep data fresh with shorter expiration limits, cache-network strategy, or both!
  • Easy-to-use: Install package, register and configure service worker, start caching
  • Flexible: Works with GQL queries made as both fetch POST and GET requests
  • Easily exempt types of queries from being cached at the global or endpoint-specific level

Usage Notes

  • Caching is currently only supported for query-type operations. Mutations, subscriptions, etc will still run, but will not be cached.
  • Cached data normalization feature is disabled.

Contributing

Contributions are welcome. Please read CONTRIBUTE.md prior to making a Pull Request.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].