Skip to content

MikaeI/replenish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

replenish

Development utility to trigger reload of a web page in a browser (alternative to LiveReload).

Requirements

  • Node.js

Install

npm install --save-dev replenish

Usage

Add the following script to your package.json:

"scripts": {
  "replenish": "replenish"
}

Now you can add replenish to other scripts or use it from the command line: npm run replenish.

Use the npm run replenish command any time you want to perform a reload.

Example of client side setup (1s polling interval):

let timestamp = Date.now();
let request = new XMLHttpRequest();
request.onload = function() {
    if (this.status >= 200 && this.status < 400) {
        if (JSON.parse(this.response).updated > timestamp) {
            location.reload();
        }
    }
};
setInterval(() => {
    dummy = Date.now();
    request.open("GET", "./node_modules/replenish/state.json?q=" + dummy, true);
    request.send();
}, 1000);

License

MIT © Mikael Åsbjørnsson-Stensland

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published