
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
reloader-injector
Advanced tools
Insert a <script> to reload the current page or its styles into an HTML
A Node.js module to insert a <script> into an HTML, which helps reloading the document or its styles automatically
In most cases there is no need to use this module directly. Developers would rather use a higher-level wrapper content-reloader.
npm install --save-dev reloader-injector
const ReloaderInjector = require('reloader-injector');
option: Object
It creates an reloaderInjector instance.
Type: string URL
Default: '/sse'
A URL at which the client script will open a connection to the server.
This module expects the server to serve no contents other than reloader-injector-related ones under this URL. If the server will respond to requests whose URLs begin with /sse, change the value of this option.
response: http.ServerResponse
If the media type of the response is text/html, it inserts a <script> tag into the response body as the first child of <body>. The src attribute of the <script> points to the first key of reloaderInjector.clients.
response: http.ServerResponse
If the media type of the response is text/html, it inserts a <script> tag into the response body as the first child of <body>. The src attribute of the <script> points to the second key of reloaderInjector.clients.
Type: Map<string: Buffer>
This Map contains two Buffers: the first value is a JavaScript code generated by the main function of reloader-client, and the second one is a JavaScript code generated by the .legacy() method of reloader-client.
Type: string
A pathname of the URL corresponding to the url option.
const reloaderInjector = new ReloaderInjector();
reloaderInjector.clients; /*=> Map {
'/sse-95f0ec37f24542c2547b712a060e43af.js' => <Buffer 63 6f 6e 73 ...>,
'/sse-eb33250679b5d5c862ed2286a2c95e75.js' => <Buffer 2f 2a 2a 20 ...>
} */
Type: string
The same values as reloader-client's.
1. Inject a <script> tag to an HTML Response using .injectScriptTag() (or .injectLegacyScriptTag() for Microsoft browsers).
const reloaderInjector = new ReloaderInjector();
const server = createServer(({url}, res) => {
res.setHeader('content-type', 'text/html');
reloaderInjector.injectScriptTag(res);
res.end('<!doctype html><html lang="en"> ... some contents ... </html>');
});
2. Serve JavaScript of reloaderInjector.clients using its keys as a pathname of endpoints.
const server = createServer(({url}, res) => {
+ for (const [clientUrl, body] of reloaderInjector.clients) {
+ if (url === clientUrl) {
+ res.writeHead(200, {
+ 'content-type': 'application/javascript',
+ 'content-length': body.length
+ });
+
+ res.end(body);
+ return;
+ }
+ }
3. Whenever a reload should be performed, send a server-sent event to the client in the following form:
id: <any>
data: <ReloaderInjector.DOCUMENT_RELOAD_SIGNAL|ReloaderInjector.CSS_RELOAD_SIGNAL>
data must equal to either ReloaderInjector.DOCUMENT_RELOAD_SIGNAL or ReloaderInjector.CSS_RELOAD_SIGNAL.id must be different from the previous event's.ISC LICENSE © 2019 Shinnosuke Watanabe
FAQs
Insert a <script> to reload the current page or its styles into an HTML
The npm package reloader-injector receives a total of 3 weekly downloads. As such, reloader-injector popularity was classified as not popular.
We found that reloader-injector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.