File tree 4 files changed +40
-5
lines changed
4 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ var connectUtils = {
20
20
}
21
21
22
22
var template = fs . readFileSync ( config . templates . scriptTag , "utf-8" ) ;
23
-
24
23
var scriptPath = this . clientScript ( options ) ;
24
+ var async = options . getIn ( [ "snippetOptions" , "async" ] ) ;
25
25
var script ;
26
26
var override = false ;
27
27
@@ -38,7 +38,8 @@ var connectUtils = {
38
38
}
39
39
40
40
template = template
41
- . replace ( "%script%" , script ) ;
41
+ . replace ( "%script%" , script )
42
+ . replace ( "%async%" , async ? "async" : "" ) ;
42
43
43
44
return template ;
44
45
} ,
Original file line number Diff line number Diff line change @@ -158,19 +158,21 @@ module.exports = {
158
158
logSnippet : true ,
159
159
160
160
/**
161
- * SINCE 1.7.0! You can control how the snippet is injected
161
+ * You can control how the snippet is injected
162
162
* onto each page via a custom regex + function.
163
163
* You can also provide patterns for certain urls
164
164
* that should be ignored from the snippet injection.
165
165
* @property snippetOptions
166
166
* @since 2.0.0
167
+ * @param {Boolean } [async] - should the script tags have the async attribute?
167
168
* @param {Array } [blacklist]
168
169
* @param {Array } [whitelist]
169
170
* @param {RegExp } [rule.match=/<body[^>]*>/i]
170
171
* @param {Function } [rule.fn=Function]
171
172
* @type Object
172
173
*/
173
174
snippetOptions : {
175
+ async : true ,
174
176
whitelist : [ ] ,
175
177
blacklist : [ ] ,
176
178
rule : {
Original file line number Diff line number Diff line change 1
1
<script type='text/javascript' id="__bs_script__">//<![CDATA[
2
- document.write("<script async src='%script%'><\/script>".replace("HOST", location.hostname));
3
- //]]></script>
2
+ document.write("<script % async% src='%script%'><\/script>".replace("HOST", location.hostname));
3
+ //]]></script>
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ var browserSync = require ( "../../../" ) ;
4
+
5
+ var assert = require ( "chai" ) . assert ;
6
+
7
+ describe ( "E2E script with/without async attribute" , function ( ) {
8
+
9
+ it ( "serves with async" , function ( done ) {
10
+ browserSync . reset ( ) ;
11
+ var config = { open : false } ;
12
+ browserSync ( config , function ( err , bs ) {
13
+ assert . include ( bs . options . get ( "snippet" ) , "async" ) ;
14
+ bs . cleanup ( ) ;
15
+ done ( ) ;
16
+ } ) ;
17
+ } ) ;
18
+ it ( "serves without async" , function ( done ) {
19
+ browserSync . reset ( ) ;
20
+ var config = {
21
+ open : false ,
22
+ snippetOptions : {
23
+ async : false
24
+ }
25
+ } ;
26
+ browserSync ( config , function ( err , bs ) {
27
+ assert . notInclude ( bs . options . get ( "snippet" ) , "async" ) ;
28
+ bs . cleanup ( ) ;
29
+ done ( ) ;
30
+ } ) ;
31
+ } ) ;
32
+ } ) ;
You can’t perform that action at this time.
0 commit comments