npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

auto-clear-cache

v1.3.0

Published

Automatically detects new app versions, clears browser caches & storages, and reloads to ensure users always get the latest deployment.

Readme

Auto Clear Cache

A lightweight, reliable utility to automatically detect new deployments, clear browser caches, and reload your web app — ensuring users always experience the latest build.

GitHub License npm Vite JavaScript

📦 Package: npm
📚 Source: GitHub


Features

  • ✅ Detects new versions and new deployments via version.json
  • 🧹 Clears browser data: Cache, LocalStorage, SessionStorage, Cookies, IndexedDB, and Service Workers
  • 🔁 Optional clear on every deploy using buildId
  • ⏱️ Optional periodic cache cleanup (e.g. every 12h / 24h)
  • ⚙️ Fully configurable with lifecycle callbacks
  • 💡 Works with Vite, Vue, Nuxt, React, Next.js, Angular, Svelte, and plain JavaScript
  • 🚀 Includes a Vite plugin for automatic version/build generation
  • 🧱 Safe for SSR, PWA, and offline-aware apps
  • 📦 Ships as built & minified dist only on npm

Installation

npm install auto-clear-cache
# or
yarn add auto-clear-cache
# or
pnpm add auto-clear-cache

Quick Start

1️⃣ Add Vite Plugin

// vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { versionPlugin } from "auto-clear-cache";

export default defineConfig({
  plugins: [vue(), versionPlugin()],
});

This generates a version.json file on every build.


2️⃣ Use in App Entry

// main.ts
import autoClearCache from "auto-clear-cache";

autoClearCache({
  askUserBeforeReload: true,
});

Default behavior:

  • Fetches version.json
  • Clears all browser caches on change
  • Reloads the app

Framework Integrations

Vue 3

import { createApp } from "vue";
import App from "./App.vue";
import autoClearCache from "auto-clear-cache";

autoClearCache({
  onVersionChange: (oldV, newV) => console.log(`Updating ${oldV} → ${newV}`),
});

createApp(App).mount("#app");

Nuxt 3

// plugins/version-check.client.ts
import { defineNuxtPlugin } from "#app";
import autoClearCache from "auto-clear-cache";

export default defineNuxtPlugin(() => {
  autoClearCache({
    path: "/version.json",
    askUserBeforeReload: true,
  });
});

Must use .client.ts.


React (Vite)

import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import autoClearCache from "auto-clear-cache";

autoClearCache().then(() => {
  ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
});

Next.js (App Router)

"use client";
import { useEffect } from "react";
import autoClearCache from "auto-clear-cache";

export default function VersionChecker() {
  useEffect(() => {
    autoClearCache({
      path: "/version.json",
      askUserBeforeReload: true,
    });
  }, []);

  return null;
}

Vanilla JS

<script type="module">
  import autoClearCache from "auto-clear-cache";
  autoClearCache();
</script>

Configuration

autoClearCache / checkVersionAndReload

| Option | Type | Default | Description | | ------------------- | -------- | --------------- | -------------------------- | | path | string | /version.json | Version file path | | localStorageKey | string | app_version | Stored version key | | clearEverything | boolean | true | Clear all browser data | | forceClearOnBuild | boolean | false | Clear on every deploy | | clearIntervalMs | number | null | Periodic clearing interval | | delayBeforeReload | number | 0 | Reload delay (ms) | | askUserBeforeReload | boolean | false | Confirm before reload | | verbose | boolean | true | Enable logs | | onVersionChange | function | — | When version/build changes | | onVersionMatch | function | — | When version matches | | onError | function | — | On error |


clearAllBrowserData

| Option | Type | Default | Description | | --------------------- | -------- | ------- | -------------------------- | | clearLocalStorage | boolean | true | Clear LocalStorage | | clearSessionStorage | boolean | true | Clear SessionStorage | | clearCacheStorage | boolean | true | Clear CacheStorage | | clearCookies | boolean | true | Clear Cookies | | clearIndexedDB | boolean | true | Clear IndexedDB | | clearServiceWorkers | boolean | true | Unregister Service Workers | | excludeLocalStorage | string[] | [] | Keys to preserve | | excludeCookies | string[] | [] | Cookies to preserve |


Advanced Examples

Clear on Every Deploy

autoClearCache({
  forceClearOnBuild: true,
});

Periodic Cleanup (24h)

autoClearCache({
  clearIntervalMs: 24 * 60 * 60 * 1000,
});

Preserve Auth Data

autoClearCache({
  onVersionChange: async () => {
    await clearAllBrowserData({
      excludeLocalStorage: ["auth_token"],
      excludeCookies: ["session_id"],
    });
  },
});

Changelog

See full changelog → CHANGELOG.md

v1.3.0

  • Default export support (autoClearCache())
  • Clear cache on every deploy using forceClearOnBuild
  • Periodic cache cleanup via clearIntervalMs
  • Added buildId to version.json
  • Library build & obfuscated dist output
  • Improved SSR and offline safety
  • Documentation overhaul with advanced guides

v1.2.0

  • Added Nuxt 3 and Next.js integrations
  • Introduced lifecycle callbacks and exclusions
  • Added delayBeforeReload and askUserBeforeReload
  • Improved Service Worker and IndexedDB cleanup
  • Enhanced console output and verbose logging

Author

Kerolos Zakaria
PortfolioGitHubVS Code MarketplacenpmLinkedIn


License

MIT © 2025 Kerolos Zakaria