# inject-lr-script

> inject live reload into HTML content

Latest version **2.2.0** (published 2019-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install inject-lr-script
pnpm add inject-lr-script
yarn add inject-lr-script
bun add inject-lr-script
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2019-11-01 |
| First published | 2015-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | inject, live, reload, tiny-lr, lr, tiny, tinyreload, html |

## Links

- npm: https://www.npmjs.com/package/inject-lr-script
- Repository: https://github.com/mattdesl/inject-lr-script
- Issues: https://github.com/mattdesl/inject-lr-script/issues
- npm.io page: https://npm.io/package/inject-lr-script

## Dependencies (1)

- [resp-modifier](https://npm.io/package/resp-modifier.md) ^6.0.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2019-11-01
- 2.1.0 — 2017-01-06
- 2.0.0 — 2016-02-11
- 1.2.0 — 2016-01-18
- 1.1.0 — 2015-09-28
- 1.0.2 — 2015-09-19
- 1.0.1 — 2015-02-21
- 1.0.0 — 2015-02-17

## README

# inject-lr-script

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Inject the [LiveReload script snippet](http://feedback.livereload.com/knowledgebase/articles/86180-how-do-i-add-the-script-tag-manually) into a HTML response.

This detects `.htm` and `.html` and ensures they have `text/html` accept headers, if not yet set.

Example:

```js
var liveReload = require('inject-lr-script')
var stacked = require('stacked')
var http = require('http')
var serveStatic = require('serve-static')

var app = stacked()
app.use(liveReload())
app.use(serveStatic('app/'))

var server = http.createServer(app)
```

*Note:* This expects a `<body>` tag to be present in the HTML.

## Usage

[![NPM](https://nodei.co/npm/inject-lr-script.png)](https://www.npmjs.com/package/inject-lr-script)

#### `middleware = liveReload([opt])`

Returns a function `middleware(req, res, next)` which injects a LiveReload `<script>` tag into the body of an HTML script.

Options:

- `port` the live reload server port, default 35729
- `host` the host, default `localhost`
- `path` the script path, default `'/livereload.js?snipver=1'`
- `local` if true, the script will ignore the `port` and `host` and assumes its hosted locally on the same domain, default false
- `type` the script type, default `"text/javascript"`, could also be `"module"` for ES modules
- `defer` a boolean whether to add this attribute to the script tag, default `true`
- `async` a boolean whether to add this attribute to the script tag, default `true`

You can also change the options at runtime:

```js
var liveReload = require('inject-lr-script')

var liveInjector = liveReload()
handler.use(function (req, res, next) {
  if (liveReload) {
    liveInjector.host = myHost
    liveInjector.port = myPort
    liveInjector(req, res, next)
  } else {
    next()
  }
})
```

## See Also

- [inject-lr-script-stream](https://github.com/yoshuawuyts/inject-lr-script-stream) - a simpler, streaming approach
- [connect-livereload](https://github.com/intesso/connect-livereload) - a similar approach

## Changelog

- 2.x - major refactor: simplified and uses a connect-style middleware to improve performance/stability
- 1.x - uses Beefy to try and auto-detect mime type based on response events

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/inject-lr-script/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/inject-lr-script · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
