1. About Nuxt Image
Nuxt Image is a module that allows you to optimize images in your Nuxt project. It is built on top of the native <img> tag and provides a set of directives to optimize images.
It is crucial for performance optimization and to ensure that images are displayed correctly on different devices and screen sizes. Also to provide an ability to use responsive images from CDN that are easily managed and updated.
You can learn more about Nuxt Image here.
2. Default Configuration
Nexus AI uses recommended configuration of Nuxt Image.
image: {
format: ["webp"],
screens: { // Screen sizes are from Tailwind CSS
xs: 320,
sm: 640,
md: 768,
lg: 1024,
xl: 1280,
xxl: 1536,
"2xl": 1536,
},
},
3. Optimization Techniques
Typical optimization techniques are:
- Using
formatattribute to control the image format. Default iswebp. - Using
fitattribute to control how the image is resized to fit the container. - Using
widthandheightattributes to control the size of the image. Responsive images are automatically generated. - Using
altattribute to provide a description of the image for accessibility. - Using
loadingattribute to control the load asynchronously or not. - Using
preloadattribute to control the preloading behavior of the image.
Here is an example of how to use these attributes:
<NuxtImg
src="/img/about.jpg"
width="600"
height="400"
format="webp"
fit="cover"
:preload="true"
alt="Hero Image"
class="rounded-lg"
/>
4. Image Formats and CDN Support
webp is the current most recommended image format for modern browsers. It is supported by all modern browsers and provides a good balance between image quality and file size.
Nexus AI do not use any CDN for images. All images are served from locally using nuxt-image module. Nuxt Image module uses IPX to serve images from static folder.