@@ -64,7 +64,7 @@ function rocket_browser_cache_busting( $src, $current_filter = '' ) {
6464 $ hosts = get_rocket_cnames_host ( array ( 'all ' , 'css_and_js ' , $ extension ) );
6565 $ hosts [] = parse_url ( home_url (), PHP_URL_HOST );
6666 $ hosts_index = array_flip ( $ hosts );
67- list ( $ file_host , $ relative_src_path ) = get_rocket_parse_url ( $ full_src );
67+ list ( $ file_host , $ relative_src_path, $ scheme , $ query ) = get_rocket_parse_url ( $ full_src );
6868
6969 if ( $ file_host == '' ) {
7070 $ full_src = home_url () . $ src ;
@@ -74,7 +74,7 @@ function rocket_browser_cache_busting( $src, $current_filter = '' ) {
7474 return $ src ;
7575 }
7676
77- $ relative_src_path = ltrim ( $ relative_src_path , '/ ' );
77+ $ relative_src_path = ltrim ( $ relative_src_path . ' ? ' . $ query , '/ ' );
7878 $ full_src_path = ABSPATH . dirname ( $ relative_src_path );
7979 /*
8080 * Filters the cache busting filename
@@ -140,7 +140,9 @@ function rocket_cache_dynamic_resource( $src ) {
140140
141141 $ full_src = ( substr ( $ src , 0 , 2 ) === '// ' ) ? rocket_add_url_protocol ( $ src ) : $ src ;
142142
143- switch ( current_filter () ) {
143+ $ current_filter = current_filter ();
144+
145+ switch ( $ current_filter ) {
144146 case 'script_loader_src ' :
145147 $ extension = '.js ' ;
146148 break ;
@@ -152,7 +154,7 @@ function rocket_cache_dynamic_resource( $src ) {
152154 $ hosts = get_rocket_cnames_host ( array ( 'all ' , 'css_and_js ' , $ extension ) );
153155 $ hosts [] = parse_url ( home_url (), PHP_URL_HOST );
154156 $ hosts_index = array_flip ( $ hosts );
155- list ( $ file_host , $ relative_src_path ) = get_rocket_parse_url ( $ full_src );
157+ list ( $ file_host , $ relative_src_path, $ scheme , $ query ) = get_rocket_parse_url ( $ full_src );
156158
157159 if ( $ file_host == '' ) {
158160 $ full_src = home_url () . $ src ;
@@ -162,7 +164,8 @@ function rocket_cache_dynamic_resource( $src ) {
162164 return $ src ;
163165 }
164166
165- $ relative_src_path = ltrim ( $ relative_src_path , '/ ' );
167+ $ relative_src_path = ltrim ( $ relative_src_path . '? ' . $ query , '/ ' );
168+ $ full_src_path = ABSPATH . dirname ( $ relative_src_path );
166169 /*
167170 * Filters the dynamic resource cache filename
168171 *
@@ -184,11 +187,21 @@ function rocket_cache_dynamic_resource( $src ) {
184187 return $ src ;
185188 }
186189
190+ if ( 'style_loader_src ' === $ current_filter ) {
191+ if ( ! class_exists ( 'Minify_CSS_UriRewriter ' ) ) {
192+ require ( WP_ROCKET_PATH . 'min/lib/Minify/CSS/UriRewriter.php ' );
193+ }
194+ // Rewrite import/url in CSS content to add the absolute path to the file
195+ $ file_content = Minify_CSS_UriRewriter::rewrite ( $ response ['body ' ], $ full_src_path );
196+ } else {
197+ $ file_content = $ response ['body ' ];
198+ }
199+
187200 if ( ! is_dir ( $ cache_busting_paths ['bustingpath ' ] ) ) {
188201 rocket_mkdir_p ( $ cache_busting_paths ['bustingpath ' ] );
189202 }
190203
191- rocket_put_content ( $ cache_busting_paths ['filepath ' ], $ response [ ' body ' ] );
204+ rocket_put_content ( $ cache_busting_paths ['filepath ' ], $ file_content );
192205
193206 return $ cache_busting_paths ['url ' ];
194207}
0 commit comments