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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@radixiot/react-cache-buster

v0.1.3

Published

This package allows clients to automatically check the new version or git commit hash when a new version is released in the production environment, and if a new version is published, clearing the cache and reload the page.

Downloads

11

Readme

React Cache Buster

NPM

About the Package

Based on a project originally written by CagriAldemir, this package allows clients to automatically check the new version or git commit hash when a new version is released in the production environment, and if a new version is published, clearing the cache and reload the page. You can find an example project under the example folder.

Installation

npm install react-cache-buster

#or

yarn add react-cache-buster

Usage

Add a new script to package.json

"scripts": {
  #...
  "generate-meta-tag": "node ./node_modules/react-cache-buster/dist/generate-meta-tag.js"
  #...
}

And then, change your build script like below;

"scripts": {
  "build": "yarn generate-meta-tag && react-scripts build"

  #or

  "build": "npm run generate-meta-tag && react-scripts build"
}

The "generate-meta-tag" script command creates a file named "meta.json" under the public folder under the root directory of your project and writes the current package.json version and the current git hash into the created file.

import React from 'react';
import CacheBuster from 'react-cache-buster';
import { version } from '../package.json';
import Loading from './loading';

const App = () => {
  const isProduction = process.env.NODE_ENV === 'production';
  const propertyToCheck = 'version'; // value can be either 'version' or 'hash'
  return (
    <CacheBuster
      currentValue={version or hash}
      propertyToCheck={propertyToCheck}
      isEnabled={isProduction} //If false, the library is disabled.
      isVerboseMode={false} //If true, the library writes verbose logs to console.
      loadingComponent={<Loading />} //If not pass, nothing appears at the time of new version check.
    >

      //Your actual root component...

    </CacheBuster>
  );
};

export default App;

You can now build and go on production as before.

The process works as follows;

  • When you run the build script, the "generate-meta-tag" script writes the current package.json version and current git hash into meta.json and then the build process continues.
  • When the client opens the website, the CacheBuster component makes a request to the "/meta.json" file (with cache-busting querystring variable) located in the root.
  • Although the website is initially loaded via cache, the updated version data is obtained through the request since XHR requests are not kept in the cache.
  • Then, the current version of the cached project is compared with the version received over the request.
  • If the logic determines that a cache refresh is needed based on what is configured, either the version or git hash, the whole cache is deleted and the project is reloaded.

Contact

Original Author Twitter: @CagriAldemir

Original Author Mail: [email protected]

License

MIT © CagriAldemir