Hey friend, Did you know there are 4 levels of Caching in Next.js? Next.js caches for different reasons. In today's newsletter, we're diving into the world of Next.js caching โ a powerful feature that can significantly improve your application's performance. But before we dive into the newsletter, Here is a quick annoucement,I'm running a exclusive live workshop on Next.js. It will be 3-4 hours long. I'm ironing out the final details. โYou can check the landing page here โ๏ธ. It will make you a more confident Next.js Dev and will teach you how to build production-ready apps. We won't be shying from complex topics and diving into them all. If you are interested, you can click the below button to join the waitlist.
The waitlist gets first dibs and special launch bonuses and discounts. -- Anyway, back to our newsletter. If you prefer watching a video instead on the 4 Levels of Caching, then check out this video right here โ๏ธ else keep reading. โ ๐ฟ Our Weekly Snack: Caching in Next.jsNext.js offers a multi-layered caching system that helps you deliver content faster to your users. Now, What is Caching? Caching is like having a box of your favorite cookies ๐ช at the ready, so you don't have to wait to bake them every time you want one. โฉ The job of Next.js Caching system is to speed up data retrieval by storing frequently accessed data in a faster location. Let's break down the 4๏ธโฃ key players. Here is a quick diagram, ๐ Request MemoizationImagine your app constantly bombarding the client with the same questions. Request memoization prevents this by caching function calls on the client-side. This means if your app needs the same data twice, it can retrieve it from the cache instead of making another request. We can achieve the same with memoization in React. ๐๏ธ Data CacheThis is where things get interesting ๐ง. Next.js automatically caches data fetched from the server. By default, this cached data can live forever (or at least until the next ice age).โ๏ธ But fear not! You can configure the data cache to revalidate itself at specific intervals, ensuring your users always have the latest information. Additionally, you can completely invalidate cached data if needed. ๐พ Router CacheThis cache, stores the payloads of your React Server Components on the client-side. This way, when users navigate between pages, Next.js can render the page from the cache, reducing the number of requests needed to the server. ๐ Full Route CacheReact Server Component payload split by routes and HTML on the SERVER. It skips sending new requests if RSC Payload is in Router Cache because why would it? A cache's job is to make sure to check if the app has everything it needs so it checks to see if we already have the data. But, if not, it will fetch it. This is what Full Route Cache does. Now, you might be wondering, "Can I turn caching off?"Absolutely! For situations where you need fresh data every single time, Next.js provides the Keeping your cached data fresh is crucial depending on your use case.
Next.js offers the revalidate and revalidatePath functions to invalidate cached data and ensure your users see the latest updates โจ.Want to learn more? Check out my Youtube video which covers the same with in-depth practical examples โ๏ธ. To wrap up, by effectively leveraging Next.js caching, you can create blazing-fast applications that deliver a seamless user experience โก๏ธ. ๐คซ Latest Frontend NewsIf youโve been feeling discouraged about the future of software engineering because of AI products like Devin, you need to watch this video โ๏ธ ๐ค ๐ Chrome added Support for Error.cause in Chrome DevTools, you can view it here โ๏ธ.โ ๐จ Easy-to-use CSS โ๏ธ View Transitions API helpers for Next.js App Router are here. ๐ Exciting news! Next.js 14.2 has arrived. โSupabase is now GA ๐ โ ๐ฎ React 19 is right around the cornerโ Weekly Youtube Videos ๐ฅThe Frontend Developers Toolbox ๐งฐ
|
Join 6000+ subscribers reading by weekly personalized Newsletter that helps developers level up their skills through weekly Frontend and Leadership Snacks. You get a deep dive into a Tech topic, Actionable tips to excel in your career and a toolbox!
Hey Reader, Next.js has a bunch of little features that feel fun at first โ but can actually change the way you build. This weekโs snack is one of those. Thatโs the whole point of Frontend Snacks: giving you small, sharp insights that make a real difference and ones you can actually apply. Weekly Snack: after function ๐ฟ Next.js 15 introduces after() โ a new API that lets you schedule server-side code to run after the response has been sent to the browser. So your UI renders instantly, and the...
Hey Reader, So apparently Deadpool is giving a keynote at a developer conference now. Yes, Ryan Reynolds is speaking at the Postman Conference and Iโm still trying to process that ๐คฏ I recently had a conversation with a friend who really missed in-person connections. It's hard to be at home all the time and it is only when you meet like minded people in a room is when your creative juice flows. Things like I didn't know how tall you were or didn't know you had a dog etc. come up which is...
Hey Reader, ๐จ Ever wanted your website to feel like it came straight out of a Studio Ghibli movie? I just discovered a Ghibli-inspired ShadCN UI theme that brings that dreamy, hand-painted magic to your components โ and itโs absolutely stunning. If you're as obsessed with that aesthetic as I am, you're gonna love this. I also share a Github Repo you can check out too that goes along well with the video. ๐ฟ Weekly Snack: 'server-only' vs 'use server' Next.js has two easily confused directives:...