Skip to content

Conversation

henrygr
Copy link
Member

@henrygr henrygr commented Oct 29, 2026 •

What this does

A Lighthouse pass over the app, fixing everything that is fixable without an HTTPS certificate. Performance went from 0.67 to 0.93 and accessibility from 0.93 to 1.00, with every layout shift and the LCP regression removed.

Scores (mobile, LAN preview, before → after)

Category Before After
Performance 0.67 0.93
Accessibility 0.93 1.00
Best practices 0.74 0.56*
SEO 0.91 1.00
Metric Before After
FCP 1.6 s 1.6 s
LCP 7.6 s 3.2 s
CLS 0.245 0
TBT 10 ms 10 ms

* The actual audits improved, but the category is dominated by two audits worth 10 of the 20 available points — is-on-https and deprecations (Chrome's private-network deprecation) — which both require HTTPS. Excluding the HTTPS-capped audits the score is 0.94. image-size-responsive also still fails because OSM only serves 256 px tiles; fixing it would mean switching tile provider.

Other routes

The city list and venue detail routes were audited too:

Route Perf A11y Best practices SEO LCP CLS
/ 0.93 1.00 0.56* 1.00 3.2 s 0
/:cityId/venues 0.91 → 0.97 1.00 0.78* 1.00 2.6 s 0.141 → 0
/:cityId/venues/:venueId 0.80 → 0.97 1.00 0.74* 1.00 4.4 s → 2.6 s 0.128 → 0

Both routes fetched the venue list after hydration and painted a Loading… shell, so the page grew and pushed the footer down. They now prefetch the shared query in their route loader (SSR renders the real content, footer never moves), and the venue map renders a server-side street-grid skeleton — inlined SVG, no extra request — under the live map so a late map tile no longer wins the LCP race.

Changes

Performance

  • Self-hosted fonts: Lora and Playfair Display variable woff2 files now ship in the bundle with <link rel="preload">, removing the Google Fonts round trips. Metric-adjusted local Georgia fallbacks prevent reflow on swap.
  • Lazy maps: Leaflet's JS and CSS moved into dynamically imported ClientMap/ClientVenueMap, so they only load when a map mounts.
  • LCP poster: the home map's server-rendered poster (map-poster.avif, 29 KB) is preloaded with fetchpriority="high"; the live map fades in on top of it so Chrome keeps the poster as the LCP candidate.
  • Cluster markers: overlapping pubs collapse into 44×44 clusters (react-leaflet-cluster) — fewer markers, fewer tiles, comfortable touch targets.
  • Compression + caching: Nitro now serves brotli/gzip for public assets (previously everything was uncompressed — the entry bundle drops from 278 KB to 74.8 KB brotli) and hashed assets get immutable cache headers.
  • Smaller payloads: devtools are code-split and excluded from production, and favicon.ico keeps its artwork at 16/32/48 px while dropping from 100 KB to 8.8 KB.

Accessibility

  • Skip link plus main#main-content and a single h1 per page.
  • Header brand uses a new --header-ink token so contrast passes AA in both themes (the upstream cream-dark value still failed in dark mode).
  • color-contrast and target-size now pass (1.00).

Correctness / UX

  • CLS 0: the mock-location notice is always rendered so SSR and hydration markup match, but a pre-paint data-mock-location flag on <html> (set by an inline script, applied via CSS) decides whether it takes up space — no more post-hydration push-down.
  • Hero animation no longer starts at opacity: 0, which previously made Chrome ignore the map poster as an LCP candidate.
  • Meta description, Open Graph tags and theme-color added for SEO and link previews.

Verification

  • tsc --noEmit, vitest (50/50), eslint ., prettier --check . all pass.
  • Lighthouse run twice on the LAN preview (http://10.64.124.169:3111/project2/) with Chrome headless; results stable across runs.
  • Playwright smoke test: notice visible pre-paint on LAN and hidden on localhost, poster + live map render, cluster → marker → venue navigation works, venue map renders, CLS 0, no console errors.
  • Rebased on main after Style fixes #41 (Style fixes); only Header.tsx and styles.css conflicted. Kept the contrast-safe header markup (plus upstream's z-1000) and both CSS blocks (upstream's Leaflet z-index: 900 and the cluster styles).

Notes

  • The generated baseline report (lighthouse.json) stays local and is only added to .prettierignore.
  • The /project2 base path, design and behaviour are unchanged.

AI declaration & final notes

  • This code is entirely AI generated by DeepSeek V4.1 Flash from NTNU LLM. These code changes were made to see how well an AI agent could write code with regards to accessibility and performance when given the proper tools and guidance. As we can see by the results, it does quite a good job. The rest of this PR message was written using the skill auto-pr found in .agents/skills/auto-pr/SKILL.md

@henrygr henrygr requested a review from a team as a code owner October 29, 2026 18:08
@henrygr henrygr self-assigned this Oct 29, 2026
Turn on Nitro's brotli/gzip compression for public assets (the server
previously sent everything uncompressed) and give hashed assets long-lived
immutable cache headers.

Add react-leaflet-cluster with its types so overlapping pubs collapse into a
single marker.
Serve both variable fonts from the bundle instead of Google Fonts so the
critical path has no third-party round trips, and preload them. Metric-adjusted
local Georgia fallbacks stop text from reflowing when the fonts swap in.

Map and dialog artwork now use hashed asset imports (src/assets) instead of
public/ paths built by lib/asset-url, and the favicon keeps its artwork at
16/32/48 px while dropping from 100 KB to 8.8 KB.
Leaflet's JS and CSS now load only when a map actually mounts, which keeps the
initial bundle small; the maps are client-only via dynamic imports
(ClientMap/ClientVenueMap) with a server-rendered map poster underneath.

The poster (29 KB AVIF) is the LCP element on the home page and is preloaded
with fetchpriority=high; the live map fades in on top of it instead of replacing
it, so Chrome never drops the poster as an LCP candidate.

Overlapping pubs collapse into 44x44 cluster markers that keep a comfortable
touch target, and tiles are requested from a single OSM host with a preconnect.
- The mock-location notice is always rendered but toggled before first paint by
  a data-mock-location flag on <html>, removing the 0.245 post-hydration CLS.
- Skip link, main#main-content and a single h1 per page.
- Devtools are code-split and excluded from the production bundle.
- Header brand uses --header-ink, which keeps AA contrast in both themes
  (upstream's cream-dark still failed in dark mode).
- Meta description, Open Graph tags and theme-color for SEO/social previews.
- Hero no longer starts at opacity:0, so the LCP poster counts immediately.
@henrygr henrygr force-pushed the feat/lighthouse-improvements branch from bf04b46 to 77ef466 Compare October 29, 2026 18:10
The city and venue routes fetched the venue list after hydration, so the
server painted a 'Loading…' shell and the page grew once the data arrived —
the footer was pushed down by 0.14 (city) and 0.13 (venue) of the viewport.

The shared query options now live in graphql/venues.ts and both routes
prefetch them in their loader, so the first paint already has the content and
the footer never moves. prefetchQuery swallows failures, so a cold or
unreachable API still falls back to the previous client-side loading state.
The venue map mounted after hydration, so a 256 px OSM tile arriving seconds
later became the LCP element (4.4 s on a mobile profile). The block now renders
a neutral street-grid skeleton on the server — inlined as a data URI, so it costs
no extra request — and the live map fades in on top of it, the same way the home
poster works. The skeleton stays painted underneath, which keeps it a valid LCP
candidate; venue LCP drops to 2.6 s.
@henrygr henrygr changed the title Improve Lighthouse scores: performance, accessibility and best practices [AI-GEN] Improve Lighthouse scores: performance, accessibility and best practices Oct 29, 2026
@henrygr henrygr merged commit 18ad083 into main Oct 29, 2026
1 check passed
@henrygr henrygr deleted the feat/lighthouse-improvements branch October 29, 2026 18:34
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants