Static vs. Dynamic Rendering
CONCEPTS:Static vs. Dynamic Rendering
Question Variations
- "How does Next.js decide whether to render a route statically or dynamically?"
- "What happens to the cache when you use the `cookies()` function?"
- "How can you force a route to always be dynamic even if it has no dynamic functions?"
- "What is the difference between `dynamic = 'force-dynamic'` and `revalidate = 0`?"
Why This Is Asked
Understanding when a route becomes dynamic is crucial for performance and debugging. If you expect a page to be fast and cached but accidentally use a dynamic function, your server load will increase. Interviewers want to see if you can control the rendering behavior of your segments.
Key Concepts
- Automatic Selection: How Next.js decides between static and dynamic.
- Dynamic Functions:
cookies(),headers(), andsearchParams. - Segment Config: Using
force-dynamic,force-static,error, andauto. - Impact on Caching: How dynamic rendering affects the Full Route Cache.
Question Variations
- “How does Next.js decide whether to render a route statically or dynamically?”
- “What happens to the cache when you use the
cookies()function?” - “How can you force a route to always be dynamic even if it has no dynamic functions?”
- “What is the difference between
dynamic = 'force-dynamic'andrevalidate = 0?”