Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SSG の限界を破る、再ビルド不要なサイト

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
れやか
September 21, 2025

SSG の限界を破る、再ビルド不要なサイト

フロントエンドカンファレンス東京 2025で発表したスライドです。

れやか

September 21, 2025

Transcript

31 slides
  1. Content Collections は、コンテンツを楽に・安全に扱えるようにする 機能 以下のような機能が存在する Local File や 外部 API

    からのコンテンツ取得 Markdown, HTML, JSON, YAML など様々なフォーマットに対応 Zod によるスキーマバリデーション Typescript の型生成 1. Astro Content Collectionsについて 7
  2. (例) Markdown で書いたブログ記事のコンテンツを管理する場合 const blog = defineCollection({ // 1. content

    loaderの定義 loader: glob({ base: "./src/data/blog", pattern: "**/*.md" }), // 2. スキーマバリデーション schema: z.object({ title: z.string(), description: z.string().optional(), pubDate: z.date(), }), }); export const collections = { blog }; 1. Astro Content Collectionsについて src/content/config.ts 8
  3. (例) Markdown で書いたブログ記事のコンテンツを管理する場合 // 3. コンテンツの取得 const allPosts = await

    getCollection("blog"); // すべてのコンテンツ const post = await getEntry("blog", "<post-id>"); // 特定のコンテンツ このとき、型補完が効くので便利 1. Astro Content Collectionsについて 9
  4. ビルド時ではなく、リクエスト時にコンテンツを取得してページを生 成する コンテンツストア(API 等) サーバー ユーザー コンテンツストア(API 等) サーバー ユーザー

    リクエストを送信 コンテンツの取得を要求 コンテンツデータ返却 ページ生成処理 ページHTML を返却 しかも、これは ページの一部分だけ 3. Live Content Collections とは? 16
  5. <section> <h1>最新のニュース</h1>  // ここは静的 (= 生のHTML = SSG) <img src="..."

    alt="..." /> // ここも静的 <LatestNews server:defer /> // ここは動的 (= SSR) </section> 3. Live Content Collections とは? 17
  6. (例) 外部 API にリクエストして、データを取得する const news = defineLiveCollection({ // 1.

    content loaderの定義(データ取得部分は省略) loader: liveFeedLoader("https://example.com/api/news"), // 2. スキーマバリデーション schema: z.object({ id: z.string(), title: z.string(), author: z.string().optional(), body: z.string(), }), }); export const collections = { news }; 3. Live Content Collections とは? src/live.config.ts 19
  7. (例) 外部 API にリクエストして、データを取得する // 3. コンテンツの取得 const { entries,

    error } = await getLiveCollection("news"); // すべてのコンテンツ if (error) { ... } // エラーハンドリング const { entry, error } = await getLiveEntry("news", "<news-id>"); // 特定のコンテンツ if (error) { ... } // エラーハンドリング もちろん、型補完も効く 3. Live Content Collections とは? 20
  8. Astro は、負荷を軽減するために、 cacheHint を導入 適切なキャッシュ方法を教えてくれる cacheHint は、Loader 側が設 定する (例)

    Loader が cacheHint を提供している場合 const { entry: post, error, cacheHint, } = await getLiveEntry("blog", "<post-id>"); Astro.response.headers.set("Last-Modified", cacheHint.lastModified.toString()); 4. cacheHintで負荷を軽減 24
  9. export interface CacheHint { /** Cache tags */ tags?: Array<string>;

    /** Maximum age of the response in seconds */ maxAge?: number; /** Last modified time of the content */ lastModified?: Date; } 4. cacheHintで負荷を軽減 25
  10. Next.js の ISR Astro の Live Content Collections 検証するかは開発者次 第

    自動でコンテンツを検証 ビルドした結果を保存 しておく リクエストが来るたびにコンテンツを取得 して、ページを生成する revalidate の秒数ごと に再生成 毎回取得するので、常に最新の情報を提供 できる 5. ISRとの比較 29

Other Decks in Technology