diff --git a/src/main.rs b/src/main.rs index 6df0b29..12754a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -327,6 +327,8 @@ fn status_result(status_u16: u16, mut resp: Response) -> Result /// This is the default handler for the root path `/` and displays /// the OpenAPI documentation interface. /// +/// Sends HTTP 103 Early Hints to preload critical resources for improved performance. +/// /// # Arguments /// /// * `resp` - The response object to populate @@ -339,6 +341,25 @@ fn status_result(status_u16: u16, mut resp: Response) -> Result /// /// Returns an error if the KV store lookup fails. fn swagger_ui_html(mut resp: Response) -> Result { + // Send Early Hints (103) to preload critical resources + // This allows browsers to start downloading these resources while the server + // prepares the main response, improving page load performance + let early_hints = Response::from_status(103) + .with_header( + "Link", + "; rel=preload; as=style", + ) + .with_header( + "Link", + "; rel=preload; as=script", + ) + .with_header( + "Link", + "; rel=preload; as=script", + ); + + early_hints.send_to_client(); + // Define a KV store instance using the resource link name let store: KVStore = KVStore::open(KV_STORE_NAME)?.unwrap();