LiveReload JavaScript Client

4.0.2 · active · verified Tue Apr 21

LiveReload.js is the client-side JavaScript implementation of the LiveReload protocol, designed to automatically refresh web browsers during development when file changes are detected by a compatible LiveReload server. The current stable version is 4.0.2, with releases occurring periodically for bug fixes and dependency updates. Unlike many development tools, this package is explicitly *not* recommended for direct installation or bundling by most end-users; instead, it is intended to be served and managed by a LiveReload server (e.g., LiveReload app for Mac, rack-livereload, guard-livereload, grunt-contrib-watch, python-livereload). This approach ensures compatibility and allows for server-specific customizations. It supports live CSS and image reloading, as well as full page reloads for other file types, communicating with the server via WebSockets. It differentiates itself by being solely the client aspect of a larger ecosystem, expecting a server component to drive its functionality.

Common errors

Warnings

Install

Imports

Quickstart

This HTML snippet demonstrates the most common way to include the `livereload.js` client in a web page, typically injected by a LiveReload server, enabling automatic browser reloading on file changes.

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LiveReload Demo</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h1>Hello LiveReload!</h1>
    <p>Watch this page refresh automatically.</p>

    <!-- Recommended way to include livereload.js, served by your dev server -->
    <script>
        // This script snippet is typically injected by a LiveReload server or build tool.
        // It tries to connect to the LiveReload server, usually on port 35729.
        // Replace 'localhost' and '35729' if your server uses different settings.
        document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js"></' + 'script>');
    </script>
</body>
</html>

/* style.css */
body {
    font-family: sans-serif;
    background-color: lightblue;
    color: #333;
}

h1 {
    color: darkblue;
}

view raw JSON →