Skip to content

Commit 62d906e

Browse files
shakyShaneShane Osbourne
and
Shane Osbourne
authored
fix: append to head if body not present yet - fixes #2031 (#2041)
Co-authored-by: Shane Osbourne <[email protected]>
1 parent f91440e commit 62d906e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

examples/options.snippetOptions.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
*
3+
* Install:
4+
* npm install browser-sync
5+
*
6+
* Run:
7+
* node <yourfile.js>
8+
*
9+
* This example shows how you can place the snippet anywhere.
10+
*/
11+
12+
"use strict";
13+
14+
var path = require("path");
15+
var browserSync = require("../packages/browser-sync").create();
16+
var cwd = path.join(__dirname, "..");
17+
var fixtures_dir = path.join(cwd, "packages/browser-sync/test/fixtures");
18+
19+
browserSync.init({
20+
files: [path.join(fixtures_dir, "css/*.css")],
21+
server: fixtures_dir,
22+
snippetOptions: {
23+
rule: {
24+
match: /<\/head>/i,
25+
fn: function (snippet, match) {
26+
return snippet + match;
27+
},
28+
},
29+
},
30+
});

packages/browser-sync/templates/script-tags.html

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
script.src = '%script%'.replace("HOST", location.hostname);
99
if (document.body) {
1010
document.body.appendChild(script);
11+
} else if (document.head) {
12+
document.head.appendChild(script);
1113
}
1214
} catch (e) {
1315
console.error("Browsersync: could not append script tag", e);

0 commit comments

Comments
 (0)