Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig, sessionDrivers } from "astro/config";
import { defineConfig, fontProviders, sessionDrivers } from "astro/config";
import cloudflare from "@astrojs/cloudflare";
import tailwindcss from "@tailwindcss/vite";

Expand All @@ -13,10 +13,38 @@ export default defineConfig({
// Cloudflare-KV session driver so no (id-less) SESSION KV binding is emitted
// into the generated deploy config.
session: { driver: sessionDrivers.memory() },
// Self-host the two webfonts (downloaded + subset at build time, served as
// static /_astro assets by the platform). This removes the render-blocking
// cross-origin Google Fonts stylesheet from the critical path; the <Font>
// component instead inlines @font-face CSS and preloads the body font.
fonts: [
{
provider: fontProviders.google(),
name: "Inter",
cssVariable: "--font-inter",
weights: ["400 800"],
styles: ["normal"],
subsets: ["latin"],
fallbacks: ["system-ui", "sans-serif"],
},
{
provider: fontProviders.google(),
name: "Playfair Display",
cssVariable: "--font-playfair",
weights: ["700 900"],
styles: ["normal", "italic"],
subsets: ["latin"],
fallbacks: ["Georgia", "serif"],
},
],
adapter: cloudflare({
// Plain <img> with build-emitted assets — no runtime image service / IMAGES binding.
imageService: "passthrough",
}),
// Inline the (small, ~6KB) global stylesheet into each page's <head> instead
// of emitting a render-blocking <link>. Pages are SSR'd per request, so there
// is no shared-CSS-cache benefit to give up, and FCP/LCP improve.
build: { inlineStylesheets: "always" },
vite: {
plugins: [tailwindcss()],
resolve: {
Expand Down
12 changes: 6 additions & 6 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { Font } from "astro:assets";
import "../styles/global.css";

interface Props {
Expand Down Expand Up @@ -101,12 +102,11 @@ const telemetryConfig = Astro.locals.telemetry?.clientConfig() ?? null;

<slot name="head" />

<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Playfair+Display:ital,wght@0,700;0,900;1,700;1,900&display=swap"
/>
{/* Self-hosted, served from /_astro — no cross-origin render-blocking
stylesheet. Inter is the body font, so preload it; the serif display
face is above-the-fold too, so preload it as well. */}
<Font cssVariable="--font-inter" preload />
<Font cssVariable="--font-playfair" preload />
</head>
<body>
<slot />
Expand Down
6 changes: 4 additions & 2 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
--color-paper: var(--paper);
--color-ink: var(--ink);
--color-electric: var(--electric);
--font-serif: "Playfair Display", Georgia, serif;
--font-sans: "Inter", system-ui, sans-serif;
/* Resolve to the self-hosted families registered via Astro's fonts config
(astro.config.mjs). Each var already carries optimized fallback metrics. */
--font-serif: var(--font-playfair, "Playfair Display", Georgia, serif);
--font-sans: var(--font-inter, "Inter", system-ui, sans-serif);
}

:root {
Expand Down
Loading