1 minute read

Building and Deploying Serverless Applications with NextJS and Vercel

● Code Splitting

NextJS automatically performs code splitting, creating separate bundles for each page in your application. This means that users only download the code necessary for the current page, reducing the initial load time. To further optimize your code, consider using dynamic imports to load components or modules on-demand, as discussed in the “Building a Serverless Application with NextJS” section.

Advertisement

● Caching and CDN

Vercel’s global CDN and edge network ensure that your application’s static assets and server-rendered pages are served quickly and efficiently to users around the world. To further optimize caching, consider using the Cache-Control header in your serverless functions to control how long assets are cached on the client and CDN. export default async function handler(req, res) {

// Your serverless function code here

// Set the Cache-Control header res.setHeader('Cache-Control', 'public, max-age=3600, s-maxage=86400');

This article is from: