Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SSG の限界を破る、再ビルド不要なサイト
Search
れやか
September 21, 2025
Technology
2
610
SSG の限界を破る、再ビルド不要なサイト
フロントエンドカンファレンス東京 2025で発表したスライドです。
れやか
September 21, 2025
Tweet
Share
Other Decks in Technology
See All in Technology
大規模サーバーレスAPIの堅牢性・信頼性設計 〜AWSのベストプラクティスから始まる現実的制約との向き合い方〜
maimyyym
6
3.8k
20201008_ファインディ_品質意識を育てる役目は人かAIか___2_.pdf
findy_eventslides
2
590
ガバメントクラウド(AWS)へのデータ移行戦略の立て方【虎の巻】 / 20251011 Mitsutosi Matsuo
shift_evolve
PRO
2
180
Optuna DashboardにおけるPLaMo2連携機能の紹介 / PFN LLM セミナー
pfn
PRO
2
940
三菱電機・ソニーグループ共同の「Agile Japan企業内サテライト」_2025
sony
0
130
小学4年生夏休みの自由研究「ぼくと Copilot エージェント」
taichinakamura
0
580
"プロポーザルってなんか怖そう"という境界を超えてみた@TSUDOI by giftee Tech #1
shilo113
0
170
Goに育てられ開発者向けセキュリティ事業を立ち上げた僕が今向き合う、AI × セキュリティの最前線 / Go Conference 2025
flatt_security
0
370
『OCI で学ぶクラウドネイティブ 実践 × 理論ガイド』 書籍概要
oracle4engineer
PRO
3
170
Geospatialの世界最前線を探る [2025年版]
dayjournal
0
190
プロポーザルのコツ ~ Kaigi on Rails 2025 初参加で3名の登壇を実現 ~
naro143
1
200
Modern_Data_Stack最新動向クイズ_買収_AI_激動の2025年_.pdf
sagara
0
240
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
A better future with KSS
kneath
239
18k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Building Applications with DynamoDB
mza
96
6.7k
Music & Morning Musume
bryan
46
6.8k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Statistics for Hackers
jakevdp
799
220k
The World Runs on Bad Software
bkeepers
PRO
71
11k
For a Future-Friendly Web
brad_frost
180
9.9k
Transcript
SSG の限界を破る、 再ビルド不要なサイト れやか (@reyalka_dev) 1
自己紹介 れやか (reyalka) 学生です Astroが好き 2
SSG とは、 Astroのこと 3
Astro v5.10 で追加された Live Content Collections のお話 4
1. Astro Content Collections について 5
Live Content Collections は Content Collections の拡張 まずは、Content Collections について
1. Astro Content Collectionsについて 6
Content Collections は、コンテンツを楽に・安全に扱えるようにする 機能 以下のような機能が存在する Local File や 外部 API
からのコンテンツ取得 Markdown, HTML, JSON, YAML など様々なフォーマットに対応 Zod によるスキーマバリデーション Typescript の型生成 1. Astro Content Collectionsについて 7
(例) 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
(例) Markdown で書いたブログ記事のコンテンツを管理する場合 // 3. コンテンツの取得 const allPosts = await
getCollection("blog"); // すべてのコンテンツ const post = await getEntry("blog", "<post-id>"); // 特定のコンテンツ このとき、型補完が効くので便利 1. Astro Content Collectionsについて 9
2. 従来の Content Collections の弱点 10
コンテンツはビルドごとに反映される .astro ファイル Build HTML ファイル 静的なコンテンツ しかし、この方法だとコンテンツを更新する度にビルドが必要になる →リアルタイム性が求められるコンテンツには不向き (例:ニュース、天気予報、株価情報など)
2. 従来の Content Collections の問題点 11
だったら、SSR すれば? →「静的=SSG」「動的=SSR」 2. 従来の Content Collections の問題点 12
双方にメリットがある SSG: 生のHTMLを配信できる SSR: 常に最新の情報を提供できる SSG と SSR の良いとこ取りができたらな... 2.
従来の Content Collections の問題点 13
そこで、Live Content Collections SSR SSG 2. 従来の Content Collections の問題点
14
3. Live Content Collections とは? 15
ビルド時ではなく、リクエスト時にコンテンツを取得してページを生 成する コンテンツストア(API 等) サーバー ユーザー コンテンツストア(API 等) サーバー ユーザー
リクエストを送信 コンテンツの取得を要求 コンテンツデータ返却 ページ生成処理 ページHTML を返却 しかも、これは ページの一部分だけ 3. Live Content Collections とは? 16
<section> <h1>最新のニュース</h1> // ここは静的 (= 生のHTML = SSG) <img src="..."
alt="..." /> // ここも静的 <LatestNews server:defer /> // ここは動的 (= SSR) </section> 3. Live Content Collections とは? 17
毎回データを取得するので、常に最新の情報 を提供できる しかも、Astro のコンテンツ管理機能もつい てくる 3. Live Content Collections とは?
18
(例) 外部 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
(例) 外部 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
コンテンツストア(API 等) サーバー ユーザー コンテンツストア(API 等) サーバー ユーザー リクエストを送信 コンテンツの取得を要求
コンテンツデータ返却 ページ生成処理 ページHTML を返却 3. Live Content Collections とは? 21
ユーザーからリクエストが来るたび にコンテンツを取得するのは、負荷 が高いのでは? → cacheHint で解決 3. Live Content Collections
とは? 22
4. cacheHint で負荷を軽減 23
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
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
cacheHint で提供する情報は Loader 側に委ねられる 将来的には Astro 内部で自動的に 実装されるかも? 4. cacheHintで負荷を軽減
26
5. ISR との比較 27
Live Content Collections と似たような仕組み → ISR 5. ISRとの比較 28
Next.js の ISR Astro の Live Content Collections 検証するかは開発者次 第
自動でコンテンツを検証 ビルドした結果を保存 しておく リクエストが来るたびにコンテンツを取得 して、ページを生成する revalidate の秒数ごと に再生成 毎回取得するので、常に最新の情報を提供 できる 5. ISRとの比較 29
5. まとめ 30
Live Content Collections は、SSG と SSR の 良いとこ取り 動的なコンテンツを扱うための新しい選択肢 となりうる
5. まとめ 31