Your e-commerce Next.js application needs to display real-time inventory data on product pages. Which data-fetching method would be most appropriate?
- Use client-side rendering (CSR) with WebSockets to maintain a live connection for real-time updates.
- Use server-side rendering (SSR) with a caching layer to minimize data requests and optimize performance.
- Use server-side rendering (SSR) with data fetching at runtime on the client side to ensure real-time updates.
- Use static site generation (SSG) with periodic revalidation to update inventory data at predefined intervals.
To display real-time inventory data on product pages in a Next.js e-commerce application, it's most appropriate to use server-side rendering (SSR) with data fetching at runtime on the client side. This allows you to ensure real-time updates while maintaining the benefits of server-side rendering. SSG with periodic revalidation is better for static data that doesn't change frequently. CSR with WebSockets introduces complexity and may not be as SEO-friendly. Using SSR with caching can improve performance but may not provide real-time updates.
Loading...
Related Quiz
- What are Redux selectors and why to use them?
- You've noticed that every time a parent component's state changes, a child component re-renders even though its props remain unchanged. How might you optimize the child component to prevent unnecessary re-renders?
- In terms of performance optimization, how does Redux's connect method help in preventing unnecessary re-renders?
- You're building a blog with Next.js. You want each blog post to have a unique URL based on its title, but you don't want to create a new page component for each post. How would you achieve this?
- The process that allows React to efficiently update the DOM by comparing the current and next versions of the virtual DOM is called ________.