Atila
I'm on a mission to make code simple. When not recording screencasts or courses, you may find me either writing and talking about jamstack, performance, or developer tooling.
export { Component }
export default Component
const DynamicComponent = dynamic(() => import('../components/hello'))
const DynamicComponent = dynamic(() =>
import('@components/hello').then((mod) => mod.Hello)
)
import Image from 'next/image'
import profilePic from '../public/me.png'
const Home = () => <Image src={profilePic} />
import Image from 'next/image'
const Home = () => (
<Image
src="https://path.com/image.png"
width={500}
height={500}
/>
)
⚠️
module.exports = {
images: {
domains: ['example.com', 'example2.com'],
},
}
<Image
src="/me.png"
alt="Picture of the author"
width={500}
height={500}
priority
/>
add the priority property to the image that will be the Largest Contentful Paint (LCP) element for each page
adjust sizes with CSS
when you own the service
when source has an image service
scales down to fit container width
*up to image size
exactly set sizes
scales to fit container width
scales to fit container width and height
module.exports = {
// ...
images: {
// default sizes
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
// defaults image sizes
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
// options: "default", "imgix", "cloudinary", "akamai", "custom"
loader: 'default',
// configuration path to your loader
path: '',
domains: ['https://bla.com'],
// allow import images
disableStaticImages: false,
// default minimum cache time in seconds
minimumCacheTTL: 60
}
}
before page is interactive
load immediately after interactive
load when page is idle
v14 +
experimental modules
⚠️
page components
serverless functions
static assets
type sitemapEntry = {
path: string
changefreq: string
priority: number
}
<url>
<loc>https://domain.com</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
module.exports = {
i18n: {
locales: ['default', 'en', 'de', 'fr'],
defaultLocale: 'default',
localeDetection: false,
},
trailingSlash: true,
}
import { NextRequest, NextResponse } from 'next/server'
const PUBLIC_FILE = /\.(.*)$/
export function middleware(request: NextRequest) {
const shouldHandleLocale =
!PUBLIC_FILE.test(request.nextUrl.pathname) &&
!request.nextUrl.pathname.includes('/api/') &&
request.nextUrl.locale === 'default'
return shouldHandleLocale
? NextResponse.redirect(`/en${request.nextUrl.href}`)
: undefined
}
By Atila