Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

The main page loads four blocking resources (CSS, 2x JS bundles, JSON spec) serially. HTTP 103 Early Hints allows browsers to discover and fetch these resources while the server prepares the HTML response from KV store.

Changes

  • Modified swagger_ui_html() to send HTTP 103 response with Link preload headers before the main response
  • Added preload directives for:
    • swagger-ui.css (as=style)
    • swagger-ui-bundle.js (as=script)
    • swagger-ui-standalone-preset.js (as=script)
    • openapi-spec.json (as=fetch, crossorigin)

Implementation

fn swagger_ui_html(mut resp: Response) -> Result<Response, Error> {
    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")
        .with_header("Link", "</static-assets/openapi-spec.json>; rel=preload; as=fetch; crossorigin");
    
    early_hints.send_to_client();
    
    // ... continue with normal response
}

Impact

Reduces time-to-interactive by parallelizing KV store lookup with resource fetching. Most beneficial on high-latency connections where round-trip time dominates.

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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 critical resources Nov 25, 2025
@BrooksCunningham BrooksCunningham marked this pull request as ready for review November 25, 2025 19:39
@BrooksCunningham BrooksCunningham merged commit ba774d0 into main Nov 25, 2025
1 check passed
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