
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
bs-html-injector
Advanced tools
Browsersync plugin for injecting HTML changes without reloading the browser. Requires an existing page with a <body> tag.
$ npm i browser-sync bs-html-injector
$ npm i browser-sync bs-html-injector@2
##Options
files - String|Array File watching patterns that will trigger the injection. NOTE: Ensure you are not also watching the same file through the regular Browsersync config - this will cause a full reload and the inject will not happen
browserSync.use(require("bs-html-injector"), {
files: ["app/*.html", "app/templates/**"]
});
restrictions - Array Limit the comparisons to a certain elements.
browserSync.use(require("bs-html-injector"), {
files: "app/*.html",
restrictions: ['#header', '#footer']
});
excludedTags - Array
When working from scratch within the body tag, the plugin will work just fine. But when you start
working with nested elements, you might want to add the following configuration to improve the
injecting.
browserSync.use(require("bs-html-injector"), {
files: "app/*.html",
excludedTags: ["BODY"]
});
###Example
Create a file called bs.js and enter the following: (update the paths to match yours)
// requires version 2.0 of Browsersync or higher.
var browserSync = require("browser-sync").create();
var htmlInjector = require("bs-html-injector");
// register the plugin
browserSync.use(htmlInjector, {
// Files to watch that will trigger the injection
files: "app/*.html"
});
// now run Browsersync, watching CSS files as normal
browserSync.init({
files: "app/styles/*.css"
});
###Gulp example
var gulp = require("gulp");
var browserSync = require("browser-sync").create();
var htmlInjector = require("bs-html-injector");
/**
* Start Browsersync
*/
gulp.task("browser-sync", function () {
browserSync.use(htmlInjector, {
files: "app/*.html"
});
browserSync.init({
server: "test/fixtures"
});
});
/**
* Default task
*/
gulp.task("default", ["browser-sync"], function () {
gulp.watch("test/fixtures/*.html", htmlInjector);
});
// This shows a full config file!
module.exports = function (grunt) {
grunt.initConfig({
watch: {
files: 'app/scss/**/*.scss',
tasks: ['bsReload:css']
},
sass: {
dev: {
files: {
'app/css/main.css': 'app/scss/main.scss'
}
}
},
browserSync: {
dev: {
options: {
watchTask: true,
server: './app',
plugins: [
{
module: "bs-html-injector",
options: {
files: "./app/*.html"
}
}
]
}
}
},
bsReload: {
css: "main.css"
}
});
// load npm tasks
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browser-sync');
// define default task
grunt.registerTask('default', ['browserSync', 'watch']);
};
FAQs
Inject only HTML that has changed.
The npm package bs-html-injector receives a total of 3,895 weekly downloads. As such, bs-html-injector popularity was classified as popular.
We found that bs-html-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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

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.