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

reloadsite

v1.0.9

Published

A simple live-reload server with events and ability to reload sites on demand

Downloads

17

Readme

Motivation

There are a variety of livereload modules out there so be sure to select what works for you.

This module serves the following specific purposes:

  • Events: It emits a number of events that you can listen to. This is useful in the event you want to run a few other stuff before or after the site reloads.

    • The changed event fires immediately a change is detected.
    • The reloaded event fires after the reload message has been sent to socket
  • Manual Reloads: In addition to being able to delay the reload process. You can also completely disable it using the autoReload option and instead trigger the reload process manually. This is useful where you wish to run processes before reloading and you cannot predict how long those processes will take, hence a simple delay wont cut it.

Server Side

yarn add reloadsite of course!

const reloadSite = require('reloadsite');

const serverOptions = {
  // defaults to the common livereload port 35729
  port: 35729,
};

const reloader = reloadSite(serverOptions);

const reloadOptions = {
  // You can delay reload. Value in milliseconds
  delay: 300,
  // Or disable auto reloading in favour for manual reloading
  autoReload: true,
};

reloader.watch(
  // the directories to watch
  // can be a string or array
  './public',
  reloadOptions
);

Reload manually

ReloadSite is built to enable you manually trigger auto reload. You achieve that by listening to the changed event.

// Because we set autoReload to false, we want to listen to change event and manually reload
reloader.on('changed', async function (file) {
  // Ok let's log what has happened
  console.log(`${file} changed... will reload after a bit...`);

  // we run some long process before reloading
  await some_long_running_process();

  // Manually trigger site reload
  // note passing the file that changed allows ReloadSite to figure out how to reload. See Reloading Section below
  reloader.reload(file);
});

Client Side

For the client-end, use:

<!-- Then load the simple script that executes the actual reloading -->
<script src="http://localhost:35729/reloadsite.js"></script>

Reloading

To Understand how reloading happens we first need to discuss the file extensions that ReloadSite watches by default.

File Extensions

let styleExtensions = ['css'];

let imageExtensions = [
  'jpg',
  'jpeg',
  'jpe',
  'jif',
  'jfif',
  'pjpeg',
  'pjp',
  'png',
  'svg',
  'tif',
  'tiff',
  'webp',
  'apng',
  'avif',
];

let scriptExtensions = [
  'asp',
  'aspx',
  'cgi',
  'htm',
  'html',
  'jhtml',
  'js',
  'jsa',
  'jsp',
  'php',
  'php2',
  'php3',
  'php4',
  'php5',
  'php6',
  'php7',
  'phps',
  'pht',
  'phtml',
  'shtml',
  'xml',
];

Styles and images are reloaded by editing the href and src attributes of the files and adding a timestamp in the format ?ts=24633445544. This forces the browser to reload only the affected file.

All files types under scriptExtensions above are also watched. These force the browser top reload the entire page.