perf: lazy-load ShaderGradient and fix image cache TTL
Co-authored-by: denshooter <44590296+denshooter@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,8 @@ import { getTechStack } from '@/lib/directus';
|
|||||||
import { checkRateLimit, getClientIp } from '@/lib/auth';
|
import { checkRateLimit, getClientIp } from '@/lib/auth';
|
||||||
|
|
||||||
export const runtime = 'nodejs';
|
export const runtime = 'nodejs';
|
||||||
export const dynamic = 'force-dynamic';
|
|
||||||
|
const CACHE_TTL = 300; // 5 minutes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/tech-stack
|
* GET /api/tech-stack
|
||||||
@@ -28,26 +29,24 @@ export async function GET(request: NextRequest) {
|
|||||||
const techStack = await getTechStack(locale);
|
const techStack = await getTechStack(locale);
|
||||||
|
|
||||||
if (techStack && techStack.length > 0) {
|
if (techStack && techStack.length > 0) {
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
techStack,
|
{ techStack, source: 'directus' },
|
||||||
source: 'directus'
|
{ headers: { 'Cache-Control': `public, s-maxage=${CACHE_TTL}, stale-while-revalidate=${CACHE_TTL * 2}` } }
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: return empty (component will use hardcoded fallback)
|
// Fallback: return empty (component will use hardcoded fallback)
|
||||||
return NextResponse.json({
|
return NextResponse.json(
|
||||||
techStack: null,
|
{ techStack: null, source: 'fallback' },
|
||||||
source: 'fallback'
|
{ headers: { 'Cache-Control': `public, s-maxage=${CACHE_TTL}, stale-while-revalidate=${CACHE_TTL * 2}` } }
|
||||||
});
|
);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading tech stack:', error);
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.error('Error loading tech stack:', error);
|
||||||
|
}
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{ techStack: null, error: 'Failed to load tech stack', source: 'error' },
|
||||||
techStack: null,
|
|
||||||
error: 'Failed to load tech stack',
|
|
||||||
source: 'error'
|
|
||||||
},
|
|
||||||
{ status: 500 }
|
{ status: 500 }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,15 @@ import "./globals.css";
|
|||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
import { Inter, Playfair_Display } from "next/font/google";
|
import { Inter, Playfair_Display } from "next/font/google";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
import ClientProviders from "./components/ClientProviders";
|
import ClientProviders from "./components/ClientProviders";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { getBaseUrl } from "@/lib/seo";
|
import { getBaseUrl } from "@/lib/seo";
|
||||||
import ShaderGradientBackground from "./components/ShaderGradientBackground";
|
|
||||||
|
const ShaderGradientBackground = dynamic(
|
||||||
|
() => import("./components/ShaderGradientBackground"),
|
||||||
|
{ ssr: false, loading: () => null }
|
||||||
|
);
|
||||||
|
|
||||||
const inter = Inter({
|
const inter = Inter({
|
||||||
variable: "--font-inter",
|
variable: "--font-inter",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const nextConfig: NextConfig = {
|
|||||||
// Image optimization
|
// Image optimization
|
||||||
images: {
|
images: {
|
||||||
formats: ["image/webp", "image/avif"],
|
formats: ["image/webp", "image/avif"],
|
||||||
minimumCacheTTL: 60,
|
minimumCacheTTL: 2592000,
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
protocol: "https",
|
protocol: "https",
|
||||||
@@ -169,7 +169,35 @@ const nextConfig: NextConfig = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
source: "/api/(.*)",
|
// Only prevent caching for real-time/sensitive API routes
|
||||||
|
source: "/api/n8n/(.*)",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "Cache-Control",
|
||||||
|
value: "no-store, no-cache, must-revalidate, proxy-revalidate",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/api/auth/(.*)",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "Cache-Control",
|
||||||
|
value: "no-store, no-cache, must-revalidate, proxy-revalidate",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/api/email/(.*)",
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: "Cache-Control",
|
||||||
|
value: "no-store, no-cache, must-revalidate, proxy-revalidate",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/api/contacts/(.*)",
|
||||||
headers: [
|
headers: [
|
||||||
{
|
{
|
||||||
key: "Cache-Control",
|
key: "Cache-Control",
|
||||||
|
|||||||
Reference in New Issue
Block a user