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
|
|
@ -18,13 +18,13 @@
|
|||
panel instead, since cropping a logo to 16:9 cuts it off.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useState } from 'react'
|
||||
|
||||
import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
||||
import VideoPlayer from './VideoPlayer.tsx'
|
||||
import { refHref } from '../lib/hrefs.ts'
|
||||
import { mediaUrl } from '../lib/media.ts'
|
||||
import type { FeaturedCard } from '../lib/useFrontPage.ts'
|
||||
import { useSmallImage } from '../lib/useSmallImage.ts'
|
||||
|
||||
/* Image kinds that are photographs, drawn edge to edge. Anything
|
||||
else is a logo, drawn whole. */
|
||||
|
|
@ -38,29 +38,28 @@ function hrefFor(card: FeaturedCard): string | null {
|
|||
}
|
||||
|
||||
function Picture({ card }: { card: FeaturedCard }) {
|
||||
const [failed, setFailed] = useState(false)
|
||||
const src = card.image ? mediaUrl(card.image.file) : null
|
||||
const img = useSmallImage(card.image ? mediaUrl(card.image.file) : null)
|
||||
const photo = card.image ? PHOTO_KINDS.has(card.image.kind) : false
|
||||
|
||||
if (!src || failed) {
|
||||
if (img.failed) {
|
||||
return <div className="aspect-video w-full bg-tint" />
|
||||
}
|
||||
|
||||
return photo ? (
|
||||
<img
|
||||
src={src}
|
||||
src={img.src}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
onError={() => setFailed(true)}
|
||||
onError={img.onError}
|
||||
className="aspect-video w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex aspect-video w-full items-center justify-center bg-tint p-8">
|
||||
<img
|
||||
src={src}
|
||||
src={img.src}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
onError={() => setFailed(true)}
|
||||
onError={img.onError}
|
||||
className="max-h-full max-w-full object-contain"
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { useState, useEffect, useRef } from "react";
|
||||
import { Suspense, useState, useEffect, useRef } from "react";
|
||||
import { NavLink, Link, Outlet, useLocation } from "react-router-dom";
|
||||
import { PAGE_LINKS, PAGE_SECTIONS, NAV_ACTIONS } from "../navConfig.ts";
|
||||
import Banner from "./Banner.tsx";
|
||||
|
|
@ -268,7 +268,9 @@ export default function Layout() {
|
|||
|
||||
{/* Page content */}
|
||||
<main id="main" tabIndex={-1} className="outline-none" inert={mobileMenuOpen}>
|
||||
<Outlet />
|
||||
<Suspense fallback={null}>
|
||||
<Outlet />
|
||||
</Suspense>
|
||||
</main>
|
||||
|
||||
{/*Site Footer applied to every page*/}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
|
||||
An <img> for a logo or mark that may not exist: no src, or a file
|
||||
that 404s, and it draws `fallback` instead (initials, a colour dot,
|
||||
or nothing). `src` is already resolved (mediaUrl in media.ts).
|
||||
Decorative by default (alt ""), since a logo sits next to the
|
||||
name it stands for.
|
||||
or nothing). `src` is already resolved (mediaUrl in media.ts). An
|
||||
upload loads its 640px copy first (useSmallImage). Decorative by
|
||||
default (alt ""), since a logo sits next to the name it stands for.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useState, type ReactNode } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
import { useSmallImage } from '../lib/useSmallImage.ts'
|
||||
|
||||
export default function Logo({
|
||||
src,
|
||||
|
|
@ -21,7 +23,7 @@ export default function Logo({
|
|||
className?: string
|
||||
fallback?: ReactNode
|
||||
}) {
|
||||
const [failed, setFailed] = useState(false)
|
||||
if (!src || failed) return <>{fallback}</>
|
||||
return <img src={src} alt={alt} loading="lazy" className={className} onError={() => setFailed(true)} />
|
||||
const img = useSmallImage(src)
|
||||
if (img.failed) return <>{fallback}</>
|
||||
return <img src={img.src} alt={alt} loading="lazy" className={className} onError={img.onError} />
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { Link } from "react-router-dom";
|
|||
import { get } from "../lib/api.ts";
|
||||
import { isBadId, personHref } from "../lib/hrefs.ts";
|
||||
import { mediaUrl, initials } from "../lib/media.ts";
|
||||
import { useSmallImage } from "../lib/useSmallImage.ts";
|
||||
import "./PeopleTiles.css";
|
||||
|
||||
/**
|
||||
|
|
@ -588,13 +589,9 @@ function Tile({
|
|||
}
|
||||
|
||||
function Photo({ src, name }: { src?: string | null; name: string }) {
|
||||
const [failed, setFailed] = useState(false);
|
||||
const img = useSmallImage(src);
|
||||
|
||||
useEffect(() => {
|
||||
setFailed(false);
|
||||
}, [src]);
|
||||
|
||||
if (!src || failed) {
|
||||
if (img.failed) {
|
||||
return (
|
||||
<span className="pl__initials" aria-hidden="true">
|
||||
{initials(name)}
|
||||
|
|
@ -605,11 +602,11 @@ function Photo({ src, name }: { src?: string | null; name: string }) {
|
|||
return (
|
||||
<img
|
||||
className="pl__img"
|
||||
src={src}
|
||||
src={img.src}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
onError={() => setFailed(true)}
|
||||
onError={img.onError}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import { mediaUrl, initials } from '../lib/media.ts'
|
|||
import type { ContentBlockItem } from '../lib/useContent.ts'
|
||||
import { Anchor, Paragraphs } from './InlineText.tsx'
|
||||
import { withAlpha, accentText, readableOn } from '../lib/color.ts'
|
||||
import { useSmallImage } from '../lib/useSmallImage.ts'
|
||||
|
||||
const BODY = 'var(--color-muted)'
|
||||
const WEEKDAYS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
|
||||
|
|
@ -65,10 +66,9 @@ const mapLink = (place: string) =>
|
|||
`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(place)}`
|
||||
|
||||
function Avatar({ person, size }: { person: NonNullable<ContentBlockItem['person']>; size: string }) {
|
||||
const [failed, setFailed] = useState(false)
|
||||
const src = mediaUrl(person.photo)
|
||||
return src && !failed ? (
|
||||
<img src={src} alt="" onError={() => setFailed(true)} className={`${size} shrink-0 rounded-full object-cover`} />
|
||||
const img = useSmallImage(mediaUrl(person.photo))
|
||||
return !img.failed ? (
|
||||
<img src={img.src} alt="" onError={img.onError} className={`${size} shrink-0 rounded-full object-cover`} />
|
||||
) : (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue