# Audit Performance of a SvelteKit App with Lighthouse

Yes. An agent builds your SvelteKit app, serves the production output, runs Lighthouse on its routes for mobile and desktop and ties each fix to a file in src.

[Run this on Rush](https://cloud.getrush.ai/run/lighthouse-audit/sveltekit/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads what the app loads before it measures anything. In a SvelteKit app like sveltejs/realworld, `src/app.html` is where most of the weight is decided: it links the Ionicons stylesheet from `code.ionframework.com` and a Google Fonts stylesheet with four families, each in several weights and styles, both as render-blocking `<link rel="stylesheet">` tags, then `/conduit-theme.css` from `static/`, and sets `data-sveltekit-preload-data="hover"` on the body so route data is fetched on hover. `package.json` pins `pnpm@10.20.0`, `@sveltejs/kit` 2.52, `svelte` 5.55 with `runes: true` in `svelte.config.js`, `vite` 7.3 and `@sveltejs/adapter-vercel`; the scripts are `dev`, `build`, `preview`, `lint` and `format`, and there is no test and no `.github/workflows` directory.

Then it reads the routes it will measure. `src/routes/+page.server.js` loads the global feed, the user's feed or a tag from `src/lib/api.js`, whose `base` is `https://api.realworld.show/api`, so every server render waits on that network round trip; `+layout.server.js` passes the user from `hooks.server.js`, which decodes the `jwt` cookie on each request. `article/[slug]/+page.server.js` fetches the article and its comments and renders Markdown through `marked` and `sanitize-html` on the server; `profile/@[user]` has a layout load plus `get_articles.js` for the articles and favorites tabs; `Pagination.svelte` renders page links; `PreloadingIndicator.svelte` shows while `navigating.from` is set. Nothing here is lazy-loaded or split by hand, so the agent expects one JavaScript graph per route and checks what Vite actually emitted.

With that map it runs the app the way a deployment would: `pnpm install --frozen-lockfile`, `pnpm build`, then `pnpm preview` to serve the production output on the port Vite prints. It runs the Lighthouse CLI in headless Chrome against the home page, an article page, a profile page and the login page, for mobile and desktop, several runs each, and keeps the median run's JSON. In each result it reads the Core Web Vitals, the render-blocking resources audit (which names the two external stylesheets), the unused CSS audit against `conduit-theme.css`, the font display audit, the third-party summary for the API and CDN hosts, the image audits on article author avatars, and the accessibility and best-practice checks that Lighthouse runs alongside.

Every finding is written against a file. The blocking stylesheets go to `src/app.html` with the change spelled out: self-host the icon font subset in `static/`, load the Google Fonts stylesheet with `media="print"` and `onload`, or replace it with `@font-face` rules carrying `font-display: swap`. A slow server response on the home page goes to `+page.server.js` and the API base in `src/lib/api.js`, with the measured time to first byte beside it. The report also says what Lighthouse cannot see from a sandbox: the real API's latency from a user's region, and the edge behaviour of the Vercel adapter.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Run a Lighthouse audit on this SvelteKit app and write lighthouse.md. Read package.json, svelte.config.js, src/app.html, src/hooks.server.js, src/lib/api.js and every +page.server.js and +layout.server.js under src/routes first, and note every external stylesheet, font and API host the app depends on. Install with pnpm using the lockfile, run pnpm build, and serve the production output with pnpm preview. Run the Lighthouse CLI in headless Chrome against the home page, one article page, one profile page and the login page, for mobile and desktop, three runs each, and keep the median JSON for each. Write lighthouse.md with the four category scores and Core Web Vitals per page and form factor, then the five changes that would help most, each with the file in the repository that causes it and the change to make, and a section on what a sandbox measurement cannot show. Attach the Lighthouse JSON files. Change no code; the report is the result.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is `lighthouse.md` and the median Lighthouse JSON per page and form factor, as artifacts on the session. The Markdown has a scores table per page for mobile and desktop with Largest Contentful Paint, Cumulative Layout Shift and Total Blocking Time, then five changes in order of expected effect, each naming its file: the external stylesheets in `src/app.html`, the font weights requested there, the unused rules in `static/conduit-theme.css`, the server load that waits on `api.realworld.show`, and whatever the images on article and profile pages showed.

Each change comes with the audit that found it and the numbers from the JSON, so the Markdown can be checked against the raw output. A limits section records that the API's latency from the sandbox is not a user's latency and that the preview server is not the Vercel edge.

A reviewer reads the five changes, opens the JSON for any number they doubt, and decides which to make. The repository is unchanged; a follow-up prompt to the same session can make the agreed changes and open a pull request.

## Run it on every merge to main

Add an automation to the Project with this prompt and a `github` trigger on `pull_request.closed.merged` with `branch_patterns` set to `main`, marked `read_only`, so every merge gets a fresh set of scores from the production build. The merged pull request's event follows the prompt as untrusted data; the agent reads the repository as it is after the merge.

A `schedule` trigger with a weekly `cron` in your `timezone` works for a site that changes less often. Either way the report is an artifact on the session, downloadable from its `url` for an hour without a key, or through `GET /o/{org}/sessions/{id}/artifacts/{name}` with the key.

## Why run it on Rush?

Lighthouse on a laptop measures the laptop: an open dev server, a warm cache, a fast connection to the API. The sandbox builds the production output, serves it cold, and runs headless Chrome with Lighthouse's own throttling, three times per page, so the numbers are repeatable and the raw JSON stays with the run.

The report names files, not symptoms. Render-blocking stylesheets in `src/app.html` and a server load that waits on an external API are findings a developer can act on in one sitting, and the next run on the same pages shows whether the change moved the numbers.

## Frequently asked questions

### Does the audit need a logged-in user?

No. The four pages are public: the global feed, an article, a profile and the login form. Pages behind the `jwt` cookie, such as the editor and settings, need a session the sandbox does not have; a follow-up that supplies test credentials as a Project secret can add them.

### The app is deployed on Vercel. Does the preview server give the same numbers?

Not exactly, and the report says so in its limits section. `pnpm preview` serves the same built assets and runs the same server loads, so asset size, blocking resources and layout shift carry over; time to first byte at the edge does not. Scores from the preview are a floor for the asset work, not a prediction of production.

### Will it score pages that depend on the public RealWorld API?

Yes. `src/lib/api.js` points at `api.realworld.show`, which the sandbox can reach, so server loads return real articles and the pages render as they would for a visitor. If that API is unreachable during a run, the affected pages fail to render and the report records the error rather than a score.

### Can it make the changes instead of only reporting them?

Yes, as a second step. The prompt here forbids code changes so the report is a clean baseline. Send the parked session a follow-up naming the changes to make, and it edits `src/app.html` or the route files, rebuilds, reruns Lighthouse on the same pages and opens a pull request with before and after scores.

## More SvelteKit jobs

- [Turn Linear Issues Into Pull Requests for a SvelteKit App](https://getrush.ai/run/linear-issue-to-pr/sveltekit/)
- [Review Accessibility in SvelteKit Pull Requests](https://getrush.ai/run/review-accessibility/sveltekit/)
- [Review Pull Requests Automatically in a SvelteKit App](https://getrush.ai/run/review-pull-requests/sveltekit/)

## The same job on other stacks

- [Audit Performance of an Astro Site with Lighthouse](https://getrush.ai/run/lighthouse-audit/astro/)
- [Audit Performance of a Next.js Site with Lighthouse](https://getrush.ai/run/lighthouse-audit/nextjs/)
- [Audit Performance of a Nuxt Site with Lighthouse](https://getrush.ai/run/lighthouse-audit/nuxt/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
