Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ fn status_result(status_u16: u16, mut resp: Response) -> Result<Response, Error>
/// 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
Expand All @@ -339,6 +341,25 @@ fn status_result(status_u16: u16, mut resp: Response) -> Result<Response, Error>
///
/// Returns an error if the KV store lookup fails.
fn swagger_ui_html(mut resp: Response) -> Result<Response, Error> {
// 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",
"</static-assets/swagger-ui.css>; rel=preload; as=style",
)
.with_header(
"Link",
"</static-assets/swagger-ui-bundle.js>; rel=preload; as=script",
)
.with_header(
"Link",
"</static-assets/swagger-ui-standalone-preset.js>; 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();

Expand Down