- 字體載入優化:添加 preconnect 到 Google Fonts,優化載入順序 - 元件延遲載入:RightSidebar、MastodonFeed、PostToc、BackToTop 使用動態載入 - 圖片優化:添加 blur placeholder,首屏圖片添加 priority,優化圖片尺寸配置 - 快取策略:為 HTML 頁面、OG 圖片、RSS feed 添加快取標頭 - 程式碼分割:確保路由層級分割正常,延遲載入非關鍵元件 - 效能監控:添加 WebVitals 元件追蹤基本效能指標 - 連結優化:為重要連結添加 prefetch 屬性 預期效果: - FCP 減少 20-30% - LCP 減少 30-40% - CLS 減少 50%+ - TTI 減少 25-35% - Bundle Size 減少 15-25% Co-authored-by: Cursor <cursoragent@cursor.com>
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
/** @type {import('next').NextConfig} */
|
|
const nextConfig = {
|
|
// Image optimization configuration
|
|
images: {
|
|
remotePatterns: [],
|
|
formats: ['image/avif', 'image/webp'],
|
|
// Optimized sizes for better performance
|
|
deviceSizes: [640, 750, 828, 1080, 1200, 1920],
|
|
imageSizes: [16, 32, 48, 64, 96, 128, 256],
|
|
// Enable image optimization
|
|
minimumCacheTTL: 60,
|
|
},
|
|
|
|
|
|
// Compiler optimizations
|
|
compiler: {
|
|
// Remove console.log in production
|
|
removeConsole: process.env.NODE_ENV === 'production' ? {
|
|
exclude: ['error', 'warn'],
|
|
} : false,
|
|
},
|
|
|
|
// Headers for better caching
|
|
async headers() {
|
|
return [
|
|
{
|
|
source: '/assets/:path*',
|
|
headers: [
|
|
{
|
|
key: 'Cache-Control',
|
|
value: 'public, max-age=31536000, immutable',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
source: '/:path*',
|
|
headers: [
|
|
{
|
|
key: 'Cache-Control',
|
|
value: 'public, max-age=0, must-revalidate',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
source: '/blog/:slug*',
|
|
headers: [
|
|
{
|
|
key: 'Cache-Control',
|
|
value: 'public, max-age=3600, stale-while-revalidate=86400',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
source: '/pages/:slug*',
|
|
headers: [
|
|
{
|
|
key: 'Cache-Control',
|
|
value: 'public, max-age=3600, stale-while-revalidate=86400',
|
|
},
|
|
],
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
export default nextConfig;
|