Make the site faster to load and lighter on the server
- Every page but Home, and the whole admin, loads on first visit: the main bundle drops from 579 kB to 314 kB (173 to 98 kB gzipped); a tab on an old build reloads once when a page chunk has gone - Home asks for events and the timeline alongside its own data, and the server preloads /api/front-page and the first hero photo - Hero headline rises in as one piece (it held back the page's largest paint), sized to stay within two lines; min-h in dvh; first slide fetched at high priority - Every raster upload gets a 640px copy (at upload, and at boot for older files); logos, avatars and card pictures load it and fall back to the full file - Login password checks run off the event loop; only admin requests are logged per request; ffmpeg runs at nice 19 on Linux - Page HTML is no-cache, so a deploy can't strand a cached page on missing assets; source maps are no longer linked - Migration 042: index person_awards by award - docs/performance.md, and gzip and HTTP/2 for nginx Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
be7e92417e
commit
f72a9604d2
23 changed files with 420 additions and 139 deletions
|
|
@ -33,6 +33,7 @@ import StatsBand from './sections/home/StatsBand.tsx'
|
|||
import FeaturedBand from './sections/home/FeaturedBand.tsx'
|
||||
import FeaturedTimelineRail from './sections/home/FeaturedTimelineRail.tsx'
|
||||
import Pathfinder from './sections/home/Pathfinder.tsx'
|
||||
import { get } from '../lib/api.ts'
|
||||
import { documentTitle } from '../lib/site.ts'
|
||||
import {
|
||||
useFrontPage,
|
||||
|
|
@ -105,6 +106,15 @@ const SECTIONS: Record<
|
|||
export default function Home() {
|
||||
const { data: page, error, reload } = useFrontPage()
|
||||
|
||||
// The bands below ask for events and the timeline once the front
|
||||
// page has said which of them to show. Start both now, alongside it:
|
||||
// api.ts hands the same request to the bands when they mount, so
|
||||
// the page waits for one round trip instead of two.
|
||||
useEffect(() => {
|
||||
get('/events').catch(() => {})
|
||||
get('/history').catch(() => {})
|
||||
}, [])
|
||||
|
||||
// Back to the site name when a visitor returns here from a page.
|
||||
useEffect(() => {
|
||||
document.title = documentTitle()
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
The route guard and the API are what actually say no.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Suspense, useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Link, NavLink, Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { AdminTitleContext } from "../../lib/adminTitle.tsx";
|
||||
|
|
@ -210,7 +210,9 @@ export default function AdminLayout() {
|
|||
<main className={`mx-auto w-full flex-1 px-6 py-10 ${wide ? "max-w-[82rem]" : "max-w-5xl"}`}>
|
||||
<AdminTitleContext.Provider value={titleContext}>
|
||||
<AdminWidthContext.Provider value={setWide}>
|
||||
<Outlet />
|
||||
<Suspense fallback={null}>
|
||||
<Outlet />
|
||||
</Suspense>
|
||||
</AdminWidthContext.Provider>
|
||||
</AdminTitleContext.Provider>
|
||||
</main>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { preview } from '../../lib/text.ts'
|
|||
import { postDate, useCommunityBlog, type BlogPostSummary } from '../../lib/useBlog.ts'
|
||||
import HomeLink from './home/HomeLink.tsx'
|
||||
import { accentText } from '../../lib/color.ts'
|
||||
import { useSmallImage } from '../../lib/useSmallImage.ts'
|
||||
|
||||
/* Headings for a half the admin didn't title. */
|
||||
const DEFAULTS = {
|
||||
|
|
@ -36,14 +37,14 @@ const DEFAULTS = {
|
|||
const EXCERPT_CHARS = 180
|
||||
|
||||
function PostCard({ post, accent }: { post: BlogPostSummary; accent: string }) {
|
||||
const cover = mediaUrl(post.cover_image)
|
||||
const cover = useSmallImage(mediaUrl(post.cover_image))
|
||||
const date = postDate(post.published_on)
|
||||
const authors = post.authors.map((author) => author.name).join(', ')
|
||||
|
||||
return (
|
||||
<li className="relative flex flex-col overflow-hidden rounded-2xl border border-brand/15 bg-surface shadow-sm transition-shadow hover:shadow-lg">
|
||||
{cover ? (
|
||||
<img src={cover} alt="" loading="lazy" className="aspect-video w-full object-cover" />
|
||||
{!cover.failed ? (
|
||||
<img src={cover.src} alt="" loading="lazy" onError={cover.onError} className="aspect-video w-full object-cover" />
|
||||
) : (
|
||||
<div className="aspect-video w-full bg-tint" />
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Link } from 'react-router-dom'
|
|||
import { MONTH_LABELS, type PersonRef, type TimelineItem } from '../../../lib/timeline.ts'
|
||||
import { hrefFor, logoSrc } from '../../../lib/timelineRefs.ts'
|
||||
import { initials, mediaUrl } from '../../../lib/media.ts'
|
||||
import { useSmallImage } from '../../../lib/useSmallImage.ts'
|
||||
|
||||
const KIND_NAMES: Record<TimelineItem['kind'], string> = {
|
||||
milestone: 'Milestone',
|
||||
|
|
@ -28,11 +29,11 @@ function fullMarker(item: TimelineItem): string {
|
|||
}
|
||||
|
||||
function PersonChip({ person }: { person: PersonRef }) {
|
||||
const src = mediaUrl(person.photo)
|
||||
const img = useSmallImage(mediaUrl(person.photo))
|
||||
return (
|
||||
<li className="ngu-tl__person">
|
||||
{src ? (
|
||||
<img className="ngu-tl__personPhoto" src={src} alt="" loading="lazy" />
|
||||
{!img.failed ? (
|
||||
<img className="ngu-tl__personPhoto" src={img.src} alt="" loading="lazy" onError={img.onError} />
|
||||
) : (
|
||||
<span className="ngu-tl__personPhoto ngu-tl__personPhoto--blank" aria-hidden="true">
|
||||
{initials(person.name)}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
|
|||
return (
|
||||
<section
|
||||
id="hero"
|
||||
className="relative isolate flex min-h-[92vh] items-center overflow-hidden pt-24 pb-16"
|
||||
className="relative isolate flex min-h-[92dvh] items-center overflow-hidden pt-24 pb-16"
|
||||
style={{ background: DEEP }}
|
||||
>
|
||||
{backdrop === 'photos' ? (
|
||||
|
|
@ -114,7 +114,6 @@ export default function HeroStage({ hero }: { hero: Hero | null }) {
|
|||
/* ── The words ───────────────────────────────────────────────── */
|
||||
|
||||
function Words({ hero, feature }: { hero: Hero; feature: HeroFeature }) {
|
||||
const words = hero.headline.split(/\s+/).filter(Boolean)
|
||||
const live = feature === 'livestream'
|
||||
const beside = feature !== 'none'
|
||||
|
||||
|
|
@ -153,27 +152,23 @@ function Words({ hero, feature }: { hero: Hero; feature: HeroFeature }) {
|
|||
)
|
||||
)}
|
||||
|
||||
{/* One piece, not word by word: the headline is usually the
|
||||
page's largest paint, and a staggered entrance held it back
|
||||
by over a second. Sized so an admin's headline stays within
|
||||
about two lines. */}
|
||||
<h1
|
||||
className={`font-display font-extrabold leading-[0.95] tracking-tight ${
|
||||
beside ? 'text-5xl md:text-6xl' : 'text-6xl md:text-8xl'
|
||||
className={`hp-rise font-display font-extrabold leading-[1.02] tracking-tight ${
|
||||
beside ? 'text-4xl md:text-5xl' : 'text-5xl md:text-6xl lg:text-7xl'
|
||||
}`}
|
||||
style={{ animationDelay: '60ms' }}
|
||||
>
|
||||
{words.map((word, index) => (
|
||||
<span key={`${word}-${index}`}>
|
||||
<span
|
||||
className="hp-rise"
|
||||
style={{ animationDelay: `${120 + index * 110}ms` }}
|
||||
>
|
||||
{word}
|
||||
</span>{' '}
|
||||
</span>
|
||||
))}
|
||||
{hero.headline}
|
||||
</h1>
|
||||
|
||||
{hero.subhead && (
|
||||
<p
|
||||
className="hp-rise mt-8 max-w-2xl text-lg leading-relaxed text-white/75 md:text-xl"
|
||||
style={{ animationDelay: `${200 + words.length * 110}ms` }}
|
||||
style={{ animationDelay: '180ms' }}
|
||||
>
|
||||
{hero.subhead}
|
||||
</p>
|
||||
|
|
@ -182,7 +177,7 @@ function Words({ hero, feature }: { hero: Hero; feature: HeroFeature }) {
|
|||
{(hero.primary || hero.secondary) && (
|
||||
<div
|
||||
className="hp-rise mt-10 flex flex-wrap gap-4"
|
||||
style={{ animationDelay: `${320 + words.length * 110}ms` }}
|
||||
style={{ animationDelay: '300ms' }}
|
||||
>
|
||||
{hero.primary && (
|
||||
<HomeLink
|
||||
|
|
@ -290,7 +285,13 @@ function PhotoBackdrop({ slides, seconds }: { slides: HeroSlide[]; seconds: numb
|
|||
className={`hp-slide ${i === index ? 'hp-slide--on' : ''}`}
|
||||
aria-hidden={i !== index}
|
||||
>
|
||||
<img src={mediaUrl(slide.media) ?? ''} alt={slide.alt ?? ''} loading={i === 0 ? 'eager' : 'lazy'} />
|
||||
<img
|
||||
src={mediaUrl(slide.media) ?? ''}
|
||||
alt={slide.alt ?? ''}
|
||||
loading={i === 0 ? 'eager' : 'lazy'}
|
||||
fetchPriority={i === 0 ? 'high' : 'low'}
|
||||
decoding="async"
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<div
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue