Skip to content

[Architecture] Blog load uses unnecessary internal HTTP fetch instead of direct function call #17

Description

@coderabbitai

Summary

src/routes/blog/+page.server.ts fetches posts by making an HTTP round-trip to its own API:

export async function load({ fetch }) {
  const response = await fetch('api/content'); // HTTP to itself
  const posts: Post[] = await response.json();
  return { posts };
}

This adds unnecessary latency during SSR and static builds.

Recommended Fix

Extract getPosts() into src/lib/server/posts.ts and call it directly:

// src/lib/server/posts.ts
export async function getPosts(): Promise<Post[]> { ... }

// src/routes/blog/+page.server.ts
import { getPosts } from '$lib/server/posts';
export async function load() {
  return { posts: await getPosts() };
}

Backlink: #1 | Requested by: @lora-sys

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions