How does Next.js handle server-side rendering (SSR) and static site generation (SSG)? What is ISR (Incremental Static Regeneration) in Next.js, and how does it work? How do you manage API routes in Next.js, and when would you use them? What is the difference between getServerSideProps, getStaticProps, and getInitialProps? How can you optimize performance in a Next.js application?