I Was Surprised How Next.js Cached My Server Components

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024
  • After deploying my recent project, I learned a lot about how Next.js handles caching for server components.
    Check out Daily.dev - daily.dev/
    The latest deals for developers - dealsfordevs.com/
    *Newsletter*
    Newsletter 🗞 - www.jamesqquic...
    *DISCORD*
    Join the Learn Build Teach Discord Server 💬 - / discord
    Follow me on Twitter 🐦 - / jamesqquick
    Check out the Podcast - compressed.fm/
    Courses - jamesqquick.co...
    *QUESTIONS ABOUT MY SETUP*
    Check out my Uses page for my VS Code setup, what recording equipment I use, etc. www.jamesqquic...

Комментарии • 12

  • @Aaronmoreno
    @Aaronmoreno 3 месяца назад +1

    So helpful. Thanks for breaking this down so simply

    • @JamesQQuick
      @JamesQQuick  3 месяца назад

      So glad you found it helpful!

  • @PraiseYeezus
    @PraiseYeezus 3 месяца назад +2

    Basically, if there's data that Next can't know ahead of time, like a dynamic route or query params/search params or a cookie or header, the page is dynamic. If the data you need is accessible at build time and not just request time, it will default to static. If you want to avoid static pages altogether and never deal with caching, use the 'force-dynamic' exports.

    • @mateuszhallala1561
      @mateuszhallala1561 3 месяца назад

      And query data straight from the database for every user every single time?

    • @PraiseYeezus
      @PraiseYeezus 3 месяца назад

      @@mateuszhallala1561 no, you can 1) use the cache on a per-function basis with Next.js' cache 2) use the React cache function to do the same as the first option 3) use state/local storage 4) use a timed cache like shown in the video 5) use an external cache like Redis 6) simply let it call your DB every single time, because if you needed the page to be dynamic maybe you're displaying something close to real-time data anyway (plus DBs have their own cache on-disk anyway)
      there's a ton of options depending on what you want

  • @_helloMrKeni
    @_helloMrKeni 3 месяца назад

    if your data on the page is obtained by using fetch() API, you can just set the revalidate in the fetch() API, since revalidating the data-cache will also revalidate the full-route-cache

  • @alexandrmeyer
    @alexandrmeyer 3 месяца назад

    Well, I am struggling with revalidatepath always working in dev mode, and ignoring certain cases in production. Sometimes it requires additional refresh. Still debugging, so didn't come to a conclusion yet.

  • @noeldolan518
    @noeldolan518 2 месяца назад

    V15 should fix a lot of this craziness! 😅

  • @reyghardackernen7213
    @reyghardackernen7213 2 месяца назад

    So I'm not the one confused about all of these things