Next.js Automatic Static Optimization
In this article, we will learn about Automatic static optimization in NextJS.
NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditionally. Automatic Static Optimization is a feature of NextJS with the help of which we can create hybridized pages that can be rendered server-side as well as client-side depending on the content.
In NextJS, if the page has no blocking data requirements then the page will be rendered client-side by nextjs and if the page contains getServerSideProps or getInitialProps then the page will be rendered server-side. This method helps us to create hybrid apps in nextjs which contains both server-side and client-side rendered pages.
Create NextJS Application: You can create a new NextJS project using the below command:
npx create-next-app gfg
Project Structure: It will look like this.
Add the below content in the file created above.
Now if you run the below code in the terminal then nextjs will build an optimized production build for your app in which you can see the static.js file is converted into static.html and this file is statically generated and will be rendered client-side.
npm run build