@@ -93,7 +93,7 @@ export class Reloader {
9393 const elems = Reloader . getMatches ( domData . elems , data . basename , domData . attr ) ;
9494
9595 for ( var i = 0 , n = elems . length ; i < n ; i += 1 ) {
96- this . swapFile ( elems [ i ] , domData . attr , options ) ;
96+ this . swapFile ( elems [ i ] , domData , options ) ;
9797 }
9898
9999 ( cb || function ( ) { } ) ( elems , domData ) ;
@@ -102,8 +102,9 @@ export class Reloader {
102102 const tagName = options . tagNames [ fileExtension ] ;
103103 const attr = options . attrs [ tagName ] ;
104104 return {
105- elems : document . getElementsByTagName ( tagName ) ,
106- attr : attr
105+ attr,
106+ tagName,
107+ elems : document . getElementsByTagName ( tagName )
107108 } ;
108109 }
109110
@@ -125,32 +126,46 @@ export class Reloader {
125126 return matches ;
126127 } ;
127128
128- public swapFile ( elem , attr , options ) {
129+ public swapFile ( elem , domData , options ) {
129130
131+ const attr = domData . attr ;
130132 const currentValue = elem [ attr ] ;
131133 const timeStamp = new Date ( ) . getTime ( ) ;
132134 const key = "browsersync-legacy" ;
133135 const suffix = key + "=" + timeStamp ;
134136 const anchor = getLocation ( currentValue ) ;
135137 const search = updateSearch ( anchor . search , key , suffix ) ;
136138
137- if ( options . timestamps === false ) {
138- elem [ attr ] = anchor . href ;
139- } else {
140- elem [ attr ] = anchor . href . split ( "?" ) [ 0 ] + search ;
141- }
139+ switch ( domData . tagName ) {
140+ case 'link' : {
141+ this . logger . trace ( `replacing LINK ${ attr } ` ) ;
142+ this . reloadStylesheet ( currentValue ) ;
143+ break ;
144+ }
145+ case 'img' : {
146+ this . reloadImages ( currentValue ) ;
147+ break ;
148+ }
149+ default : {
150+ if ( options . timestamps === false ) {
151+ elem [ attr ] = anchor . href ;
152+ } else {
153+ elem [ attr ] = anchor . href . split ( "?" ) [ 0 ] + search ;
154+ }
142155
143- this . logger . info ( `reloading ${ elem [ attr ] } ` ) ;
156+ this . logger . info ( `reloading ${ elem [ attr ] } ` ) ;
144157
145- setTimeout ( function ( ) {
146- if ( ! hiddenElem ) {
147- hiddenElem = document . createElement ( "DIV" ) ;
148- document . body . appendChild ( hiddenElem ) ;
149- } else {
150- hiddenElem . style . display = "none" ;
151- hiddenElem . style . display = "block" ;
158+ setTimeout ( function ( ) {
159+ if ( ! hiddenElem ) {
160+ hiddenElem = document . createElement ( "DIV" ) ;
161+ document . body . appendChild ( hiddenElem ) ;
162+ } else {
163+ hiddenElem . style . display = "none" ;
164+ hiddenElem . style . display = "block" ;
165+ }
166+ } , 200 ) ;
152167 }
153- } , 200 ) ;
168+ }
154169
155170 return {
156171 elem : elem ,
0 commit comments