Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@sharyn/browser.clearcaches

sharynjs47MIT1.0.10TypeScript support: included

Clears all the caches used by service workers, and optionally reloads the page.

clear cache, clear caches, empty cache, empty caches, delete cache, delete caches, location reload, window location reload, service workers, service workers cache, refresh page

readme

🌹 clearCaches

clearCaches: Clears all the caches used by service workers.

Installation

npm i @sharyn/browser.clearcaches
# or
yarn add @sharyn/browser.clearcaches

You can alternatively install the @sharyn/browser package, or the entire sharyn library.

Arguments

[reload=false] (boolean): Reloads the page after emptying the caches.

[hardReload=true] (boolean): If reload is true, do a forced reload.

Returns

Promise

Example

const UpdateBanner = () => (
  <div>
    A new version of the app is available!
    <a onClick={() => clearCaches(true)}>Click here to update</a>
  </div>
)

Imports

Depending on the package you are using, you can import or require clearCaches in the following ways:

// If you installed @sharyn/browser.clearcaches
import clearCaches from '@sharyn/browser.clearcaches' // smaller size, better for client bundles

// If you installed @sharyn/browser
import clearCaches from '@sharyn/browser/clearCaches' // smaller size, better for client bundles
import { clearCaches } from '@sharyn/browser' // more convenient in Node environments

// If you installed sharyn
import clearCaches from 'sharyn/browser/clearCaches' // smaller size, better for client bundles
import { clearCaches } from 'sharyn/browser' // more convenient in Node environments

This package is part of Sharyn, a collection of utilities and helpers.