Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

Adds HTTP 103 Early Hints to preload critical resources on the Swagger UI homepage, reducing page load time by allowing browsers to fetch assets while the server retrieves the HTML from KV store.

Changes

  • Modified swagger_ui_html() to send Early Hints before final response:
    • Preloads swagger-ui.css as stylesheet
    • Preloads swagger-ui-bundle.js and swagger-ui-standalone-preset.js as scripts
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();

Notes

The reference implementation in the problem statement contained as=scrypt (typo) - corrected to as=script.

Original prompt

Review the following implementation for early hints.

use fastly::http::StatusCode;
use fastly::{Error, Request, Response};

#[fastly::main]
fn main(_req: Request) -> Result<Response, Error> {
    println!("running version {}", std::env::var("FASTLY_SERVICE_VERSION")
          .unwrap_or_else(|_| "<version>".to_string()));

    let early_hints = Response::from_status(103)
        .with_header("Link", "</style>; rel=preload; as=style")
        .with_header("Link", "</script.js>; rel=preload; as=scrypt");

    early_hints.send_to_client();

    Ok(Response::from_status(StatusCode::OK)
        .with_body("Here's the real HTTP body!"))
}

You need to review the site https://http.edgecompute.app/ and identify where early hints may be implemented to improve the site performance. Propose an implementation in main.rs


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: BrooksCunningham <22921241+BrooksCunningham@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement early hints for improved site performance Implement HTTP 103 Early Hints for Swagger UI homepage Nov 25, 2025
@BrooksCunningham BrooksCunningham marked this pull request as ready for review November 25, 2025 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants