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

inject-lr-script

v2.2.0

Published

inject live reload into HTML content

Downloads

45,738

Readme

inject-lr-script

stable

Inject the LiveReload script snippet into a HTML response.

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

Example:

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

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:

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

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 for details.