Hello, my name is Myrna Sochnaeser and I'm a lead full-stack developer at L'Oreal Tech Accelerator. Tech Accelerator is an internal department dedicated to driving digital innovation at L'Oreal. We design apps to help L'Oreal staff be more productive.
Today we are going to see how we reshaped our web app architecture for performance excellence and why we decided to use Next.js. At L'Oreal, there are some factors that let us define if we have a good application, like performance, accessibility, security, etc. But today we're going to focus on performance which indirectly also lets us improve our user experience.
At Tech Accelerator, we have an architecture that all our applications rely on. Our browser will try to fetch the data or the information, the files it needs from the CDN. If you do not succeed, you will go get them from the two applications hosted on App Engine. Our backend containing all our endpoints is hosted on CloudRAM and the data is hosted on Cloud SQL. We will try to replace the two applications hosted on App Engine with Next.js and have only one application.
Let's refresh our memory while checking the different renderings we can do with Next.js. Next.js is a framework that lets us create a web application where parts of our code can be rendered either on the server or on the client. This is why we talk about client-side rendering or pre-rendered on the server. And even the pre-rendered on the server is divided into many types like server-side rendering or static-side generation or others. We at first had a single page application where we needed to download one HTML file and one big JS file for all the applications. The HTML file was almost empty and the bundled contained all the information needed. But with Next.js, we will have an index.html in the chunk or bundled.js file per page. And these files will only contain the necessary to render this specific page we are at.
How does the client-side rendering work? After building our front end, we will get two files, the index.html and the bundled.js that was stored into the CDN. Once we try to access our application, the browser will go get the index.html from the CDN and then we will download, the browser will download the JS file and execute it. And once the execution is done, the web page will be visible to the user. But we will still need to go fetch the data from the server to fit the components with the correct data and remove the loading state. So in resume, we will have a white page until we download and execute the bundled.js and the loading page until we fetch the data that we need.
With the client-side rendering, we reduce the server load as the server only needs to provide the initial HTML and JavaScript file and to also simplify the backend logic because the server will primarily act as a data API leading to a cleaner and simpler backend codebase. But on the other hand, we have a slower initial page load since the browser needs to download and execute the JavaScript before rendering the page or displaying anything.
As for the server-side rendering, the browser will get the HTML file from the server. The HTML file will be filled with the correct data. We can directly see the components filled with the correct data on the browser, but they will not be hydrated. The interaction with buttons with links won't work until we fetch and download the JS file from the CDN.
Comments