0
0
NextJSframework~20 mins

Why optimization matters for performance in NextJS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Next.js page is not optimized?

Consider a Next.js page that fetches data on the client side without any caching or optimization. What is the likely effect on user experience?

NextJS
import React from 'react';

export default function Page() {
  const [data, setData] = React.useState(null);
  React.useEffect(() => {
    fetch('/api/data').then(res => res.json()).then(setData);
  }, []);
  if (!data) return <p>Loading...</p>;
  return <p>Data loaded: {data.value}</p>;
}
AThe page loads instantly with no delay.
BThe page crashes because fetch is not supported.
CThe page shows a loading state and may feel slow due to repeated fetches.
DThe page pre-renders data on the server automatically.
Attempts:
2 left
💡 Hint

Think about what happens when data is fetched only after the page loads.

📝 Syntax
intermediate
2:00remaining
Which Next.js data fetching method improves initial load performance?

Which of these Next.js data fetching methods helps improve initial page load by pre-rendering data?

AUsing <code>getServerSideProps</code> to fetch data at request time.
BUsing <code>useEffect</code> to fetch data after page load.
CFetching data inside event handlers only.
DFetching data inside <code>componentDidMount</code> lifecycle method.
Attempts:
2 left
💡 Hint

Consider which method runs on the server before sending HTML to the browser.

state_output
advanced
2:00remaining
What is the effect of not memoizing components in Next.js?

Given a Next.js component that receives props but does not use memoization, what is the likely impact on performance?

NextJS
import React from 'react';

function Child({ value }) {
  console.log('Child rendered');
  return <p>{value}</p>;
}

export default function Parent() {
  const [count, setCount] = React.useState(0);
  return (
    <>
      <button onClick={() => setCount(count + 1)}>Increment</button>
      <Child value={count} />
    </>
  );
}
AChild component never re-renders after first render.
BChild component re-renders every time Parent re-renders, even if props are the same.
CChild component re-renders only when its props change.
DChild component causes a runtime error due to missing memo.
Attempts:
2 left
💡 Hint

Think about how React decides to re-render child components.

🔧 Debug
advanced
2:00remaining
Why does this Next.js page cause slow performance on navigation?

Examine the code below. Why might navigating to this page feel slow?

NextJS
import React from 'react';

export default function Page() {
  const [data, setData] = React.useState(null);
  React.useEffect(() => {
    async function fetchData() {
      const res = await fetch('/api/large-data');
      const json = await res.json();
      setData(json);
    }
    fetchData();
  }, []);
  if (!data) return <p>Loading large data...</p>;
  return <p>Data loaded with {data.items.length} items.</p>;
}
AThe useEffect hook runs infinitely causing a crash.
BThe page pre-renders data on the server, so no delay occurs.
CThe fetch URL is incorrect, causing a 404 error.
DThe page fetches large data on the client after load, causing delay.
Attempts:
2 left
💡 Hint

Consider when the data is fetched and how big data affects load time.

🧠 Conceptual
expert
2:00remaining
Why is code splitting important in Next.js for performance?

Next.js automatically splits code into smaller chunks. Why does this improve performance?

AIt reduces the amount of JavaScript loaded initially, speeding up page load.
BIt disables JavaScript on slow connections to improve speed.
CIt delays loading CSS until after JavaScript is fully loaded.
DIt combines all JavaScript into one big file to reduce requests.
Attempts:
2 left
💡 Hint

Think about how loading smaller files affects browser speed.