简体   繁体   English

如何更快地加载大图像 | next.js

[英]How to load big images faster | next.js

It is a full screen image.这是一个全屏图像。

  1. I use Image component我使用图像组件
  2. format of the image: wepb图片格式:webb
  3. info about the image in the photo below关于下面照片中的图像的信息

What I tried:我尝试了什么:

  1. used priority={true} next.js priority in image component在图像组件中使用的优先级={true} next.js优先级

  2. tried to compress image, its size, resolution but it still loads slow试图压缩图像,它的大小,分辨率,但它仍然加载缓慢

     <Image src={"/images/video/bg-image.webp"} layout={"fill"} objectFit={"cover"} alt={"background image"} />

在此处输入图像描述

The first time I go to the page, I have to wait at least 5-10 seconds to load an image after that the image loads fast.我第一次 go 到页面时,我必须等待至少 5-10 秒才能加载图像,然后图像加载速度很快。 How can I increase loading speed of the image?如何提高图像的加载速度?

first of all you should import Image from next/image not react, If you are testing it at local pay attention for each refresh page you have a request and it is slow, but in production mode it is different and so fast.首先你应该从下一个/图像导入图像而不是反应,如果你在本地测试它,请注意每个刷新页面你有一个请求并且它很慢,但在生产模式下它是不同的并且非常快。 If you test it online Next.js catches images and have an lazy loading algorithm for the first loading and slow loading may be related to your infrastructures of the web.如果你在线测试 Next.js 捕获图像并具有用于第一次加载和慢速加载的延迟加载算法可能与您的 web 的基础架构有关。 Also I recommend you use Next.js 12.我还建议您使用 Next.js 12。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM