Performance: RSS feed generation
RSS feed generation affects server-side build time and the size of the generated feed file, impacting initial load speed when clients fetch the feed.
import { writeFileSync } from 'fs'; import { generateRSS } from './rssUtils'; export async function build() { const posts = await fetchPostsFromCMS(); const rss = generateRSS(posts); writeFileSync('./public/rss.xml', rss); }
export async function get() { const posts = await fetchPostsFromCMS(); const rss = generateRSS(posts); return new Response(rss, { headers: { 'Content-Type': 'application/rss+xml' } }); }
| Pattern | Server Cost | Response Time | Feed Size | Verdict |
|---|---|---|---|---|
| Dynamic RSS generation per request | High CPU usage | 200-500ms delay | Variable, often large | [X] Bad |
| Static RSS generation at build | One-time CPU cost | Instant response | Optimized small size | [OK] Good |
link?
const posts = [
{ title: 'Hello', date: '2024-01-01', description: 'Intro post', slug: 'hello' }
];
export const get = () => rss({
title: 'My Blog',
site: 'https://example.com',
items: posts.map(post => ({
title: post.title,
pubDate: new Date(post.date),
description: post.description,
link: `/posts/${post.slug}`
}))
});import { rss } from '@astrojs/rss';
const posts = [
{ title: 'Post 1', date: '2024-02-01', description: 'Desc', slug: 'post-1' }
];
export const get = () => rss({
title: 'Blog',
site: 'https://blog.com',
items: posts.map(post => ({
title: post.title,
pubDate: post.date,
description: post.description,
link: `/blog/${post.slug}`
}))
});const posts = [
{ title: 'Old Post', date: '2023-12-31', slug: 'old' },
{ title: 'New Post', date: '2024-01-02', slug: 'new' }
];
export const get = () => rss({
title: 'Filtered Blog',
site: 'https://filtered.com',
items: posts
.filter(post => ??? )
.map(post => ({
title: post.title,
pubDate: new Date(post.date),
link: `/posts/${post.slug}`
}))
});
What should replace ??? to filter correctly?Pass the test and this pattern moves unknown