# hexo-browser-reloader-websocket

> A hexo plugin. Automatically reloads the browser when files are modified while the hexo-server is running.

Latest version **1.1.1** (published 2024-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install hexo-browser-reloader-websocket
pnpm add hexo-browser-reloader-websocket
yarn add hexo-browser-reloader-websocket
bun add hexo-browser-reloader-websocket
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2024-07-27 |
| First published | 2024-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 21.3 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | yoshinorin |
| Maintainers | yoshinorin |
| Keywords | websocket, hexo-plugin, hexo |

## Links

- npm: https://www.npmjs.com/package/hexo-browser-reloader-websocket
- Repository: https://github.com/yoshinorin/hexo-browser-reloader-websocket
- Issues: https://github.com/yoshinorin/hexo-browser-reloader-websocket/issues
- npm.io page: https://npm.io/package/hexo-browser-reloader-websocket

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) 8.17.1
- [hexo-log](https://npm.io/package/hexo-log.md) 4.1.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2024-07-27
- 1.1.0 — 2024-07-02
- 1.0.0 — 2024-04-14
- 1.0.0-rc3 — 2024-04-09
- 1.0.0-rc2 — 2024-04-08
- 1.0.0-rc1 — 2024-04-05

## README

[![npm version](https://badge.fury.io/js/hexo-browser-reloader-websocket.svg)](https://badge.fury.io/js/hexo-browser-reloader-websocket) [![CI](https://github.com/yoshinorin/hexo-browser-reloader-websocket/actions/workflows/ci.yml/badge.svg)](https://github.com/yoshinorin/hexo-browser-reloader-websocket/actions/workflows/ci.yml) | <sub>[Coverage Report](https://yoshinorin.github.io/hexo-browser-reloader-websocket/)</sub>

# hexo-browser-reloader-websocket

Automatically reloads the browser when files are modified while the [hexo-server](https://github.com/hexojs/hexo-server) is running. Inspired by [hexo-browsersync](https://github.com/hexojs/hexo-browsersync).

## Usage

`hexo-browser-reloader-websocket` is transparent. Once installed, just run `hexo-server`.

> [!WARNING]
> Please **DO NOT USE** in production (It means do not run `hexo-server` in production). </br>
> - <sub>Please use this plugin only for development (local environment).</sub>
> - <sub>Hexo is a static site generator. It is not intended to run `hexo-server` in production.</sub>
> - <sub>This plugin does not encrypt between the WebSocket server and client. </sub>

## Install

```sh
npm i hexo-browser-reloader-websocket
```

## Configuration

**Example (Defalut):**

```yaml
# _config.yml
browser_reloader_websocket:
  enable: true
  server:
    port: 4001
  notification:
    message: "reloadBrowser"
    wait:
      min: 150 # ms
      autoCalc:
        enable: true
        coefficient: 1.0
```

| key | type | description | default |
|---|---|---|---|
| `enable` | boolean | Manage enable or disable this plugin. | `true` |
| `port` | number | WebSocket server's port. | `4001` |
| `message` | string | [WebSocket message event data](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event). | `reloadBrowser` |
| `wait.min` | number | Minimum waiting time for reload browser after detecting file changes. Pleasse see [About wait time](https://github.com/yoshinorin/hexo-browser-reloader-websocket#about-wait-time). | `150` |
| `wait.autoCalc.enable` | boolean | Calculate the waiting time for the reload browser after detecting file changes based on the number of routes. Pleasse see [About wait time](https://github.com/yoshinorin/hexo-browser-reloader-websocket#about-waitautocalc-formula). | `true` |
| `wait.autoCalc.coefficient` | number | Coefficient for calculate wait time if autoCalc is enabled. | `1.0` |

### About wait time

Reloading the browser by this plugin may be faster than the hexo-server's [router](https://hexo.io/api/router) updating if there are few routes or a lot of routes. The router updating speed depends on the number of post, pages, assets, tags, categories...etc. Also it depends on theme, plugins and machine power etc.

The `wait` option for resolve this, wait a little bit after file change detection before starting the browser reload.

### About `wait.autoCalc` calculation formula

If the `wait.autoCalc.enabled` option is `true`, the plugin calculates the waiting time based on the number of routes. Below is a calculation formula.

```text
// calculation formula
(<number of routes> / 10) * <autoCalc.coefficient> = wait(ms)

// example
(1200 / 10) * 0.9 = 108ms
```

## Logger

Please see [logger](./docs/logger.md) docs if you need.

---
_Source: https://npm.io/package/hexo-browser-reloader-websocket · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
