@@ -32,6 +32,9 @@ pub struct HtmlShell<'a> {
32
32
content : Cow < ' a , str > ,
33
33
/// The ID of the element into which we'll interpolate content.
34
34
root_id : String ,
35
+ /// The path prefix to use.
36
+ #[ cfg_attr( not( feature = "preload-wasm-on-redirect" ) , allow( dead_code) ) ]
37
+ path_prefix : String ,
35
38
}
36
39
impl < ' a > HtmlShell < ' a > {
37
40
/// Initializes the HTML shell by interpolating necessary scripts into it and adding the render configuration.
@@ -87,6 +90,7 @@ impl<'a> HtmlShell<'a> {
87
90
scripts_after_boundary : Vec :: new ( ) ,
88
91
content : "" . into ( ) ,
89
92
root_id : root_id. into ( ) ,
93
+ path_prefix : path_prefix. into ( ) ,
90
94
}
91
95
}
92
96
@@ -155,8 +159,19 @@ impl<'a> HtmlShell<'a> {
155
159
156
160
self . head_after_boundary . push ( dumb_redirect. into ( ) ) ;
157
161
self . scripts_after_boundary . push ( js_redirect. into ( ) ) ;
158
- // TODO Interpolate a preload of the Wasm bundle after the interpolation boundary
159
- // TODO Do we need any content in here?
162
+ #[ cfg( feature = "preload-wasm-on-redirect" ) ]
163
+ {
164
+ // Interpolate a preload of the Wasm bundle
165
+ // This forces the browser to get the bundle before loading the page, which makes the time users spend on a blank screen much shorter
166
+ // We have no leading `/` here because of the `<base>` interpolation
167
+ // Note that this has to come before the code that actually loads the Wasm bundle
168
+ // The aim of this is to make the time loading increase so that the time blanking decreases
169
+ let wasm_preload = format ! (
170
+ r#"<link rel="preload" href="{path_prefix}/.perseus/bundle.wasm" as="fetch" />"# ,
171
+ path_prefix = self . path_prefix
172
+ ) ;
173
+ self . head_before_boundary . push ( wasm_preload. into ( ) ) ;
174
+ }
160
175
161
176
self
162
177
}
0 commit comments