You have migrated an API endpoint to the Next.js App Router. It works perfectly in development ( next dev ). However, once you build and deploy to production, the endpoint behaves strangely. You update a record in your database, hit the endpoint to fetch the updated list, and receive the old data. No matter how many times you refresh, the data remains stale until you rebuild the application. This is not a bug in your database logic. It is a fundamental misunderstanding of how the App Router handles caching compared to the Pages Router. The Root Cause: Static by Default In the older Pages Router ( pages/api ), every API route was treated as a Dynamic Serverless Function . It executed on every request. In the App Router ( app/api ), Next.js inverts this paradigm. Route Handlers are Static by Default . When you run next build , Next.js analyzes your Route Handlers. It will automatically cache the response of a GET handler at build time and...
Practical programming blog with step-by-step tutorials, production-ready code, performance and security tips, and API/AI integration guides. Coverage: Next.js, React, Angular, Node.js, Python, Java, .NET, SQL/NoSQL, GraphQL, Docker, Kubernetes, CI/CD, cloud (Amazon AWS, Microsoft Azure, Google Cloud) and AI APIs (OpenAI, ChatGPT, Anthropic, Claude, DeepSeek, Google Gemini, Qwen AI, Perplexity AI. Grok AI, Meta AI). Fast, high-value solutions for developers.