English 中文(简体)
如何在反应 j中更快地装载S3bucket图像[封闭]
原标题:How to load S3 bucket image s faster in react js [closed]
Closed. This question needs to be more focused. It is not currently accepting answers.

I m uploading high quality images in S3 bucket which can be upto 50 mb. When retrieving those images in react app it s shows down the app.

在从第3页收到这种图像后,我怎么能够更快地或以网络格式提供这种图像?

我正在寻找解决办法,使我能够改变反应中的网络形象。

问题回答

我假定你会再次谈论要求下载网络形象的拖延。 如果你真的有形象,那么把问题与你的前端守则重新统一起来是lag的。 假设你的建议是正确的,它只是一个庞大的档案,掩盖了网络:

你可以做些什么来缓解这种情况。

  1. 创造白喉功能,每当你上载一个图像,使图像多变,给你低分辨率、高分辨率、高分辨率,然后是原始照片。

    a. Serve only reduced quality images or b. Fetch and serve the lower quality images first as they will load much faster, in the background you can fetch the higher quality images and replace it with the higher quality image

  2. 添加海滩头盔,储存浏览器中的图像

  3. 你们的架构如何看待,但你们也可以看一看一去云层的ach灭。

如果你与客户方的图像直接挂钩,你在浏览器试图把你应研究的所有资源加在图像标签上<代码>上载荷=“lazy”。 因此,图像不会阻碍整个网页的装载。

最后,一个纯粹的联合解决办法 = 装饰(拉齐负荷)的方式是,内容不是确定电弧特性,然后执行一个文字,一旦电离层移动,将图像装上。


<html>
   <img data-lazysrc= http://www.amazingjokes.com/images/20140902-amazingjokes-title.png />
</html>

<script>  

function ReLoadImages(){
   // jQuery
    $( img[data-lazysrc] ).each( function(){
        //* set the img src from data-src
        $( this ).attr(  src , $( this ).attr(  data-lazysrc  ) );
        }
    );

  // vanilla
document.querySelectorAll( img[data-lazysrc] ).forEach(function(img) {
  // Set the img src from data-src
  img.src = img.getAttribute( data-lazysrc );
});
}
document.addEventListener( readystatechange , event => {
    if (event.target.readyState === "interactive") {  //or at "complete" if you want it to execute in the most last state of window.
        ReLoadImages();
    }
});
</script>

或复读解决办法(见后遗)

// React LazyImage.jsx

import React, { useEffect, useRef, useState } from  react ;

const LazyImage = ({ src, alt }) => {
  const imgRef = useRef();
  const [isLoaded, setIsLoaded] = useState(false);

  useEffect(() => {
    const observer = new IntersectionObserver(
      (entries) => {
        entries.forEach((entry) => {
          if (entry.isIntersecting) {
            const img = new Image();
            img.src = src;
            img.onload = () => {
              imgRef.current.src = src;
              setIsLoaded(true);
            };
            observer.unobserve(imgRef.current);
          }
        });
      },
      { threshold: 0.1 }
    );

    observer.observe(imgRef.current);

    return () => {
      observer.disconnect();
    };
  }, [src]);

  return (
    <img
      ref={imgRef}
      src={isLoaded ? src :   }
      alt={alt}
      style={{ opacity: isLoaded ? 1 : 0 }}
    />
  );
};

export default LazyImage;






相关问题
Mount windows shared drive to MWAA in bootscript

In MWAA startup script sudo yum install samba-client cifs-utils -y sudo mount.cifs //dev/test/drop /mnt/dev/test-o username=testuser,password= pwd ,domain=XX Executing above commonds giving error - ...

How to get Amazon Seller Central orders programmatically?

We have been manually been keying Amazon orders into our system and would like to automate it. However, I can t seem to figure out how to go about it. Their documentation is barely there. There is: ...

Using a CDN like Amazon S3 to control access to media

I want to use Amazon S3/CloudFront to store flash files. These files must be private as they will be accessed by members. This will be done by storing each file with a link to Amazon using a mysql ...

unable to connect to database on AWS

actually I have my website build with Joomla hosted on hostmonster but all Joomla website need a database support to run this database is on AWS configuration files need to be updated for that I ...

Using EC2 Load Balancing with Existing Wordpress Blog

I currently have a virtual dedicated server through Media Temple that I use to run several high traffic Wordpress blogs. Both tend to receive sudden StumbleUpon traffic surges that (I m assuming) ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

热门标签