Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- react native navigation
- 리액트 네이티브 map
- 리액트 네이티브
- 리액트 네이티브 네비게이션
- 자바스크립트
- 리액트쿼리
- ui로직
- 프론트엔드 개발블로그
- 리액트쿼리 무한스크롤
- 리액트 무한스크롤
- FlatList
- expo-location
- HTML
- 비지니스로직
- 리액트 네이티브 캐러셀
- JavaScript
- 리액트 사진크기
- react native routes
- 부트캠프항해
- 리액트네이티브 라우트
- 네이티브 css
- react
- react-native
- 리액트
- React Native
- 무한스크롤
- 리액트네이티브 검색
- 전역상태관리
- React-qurey
- 플랫리스트
Archives
- Today
- Total
솧디의 개발로그
속도저하 성능개선하기! [이미지 리사이징] 본문


현재 만들고 있는 사이트의 모습입니다. 사이트 특성상 사진 업로드가 많습니다.
사진을 대용량으로 많이 받아오다보니 속도가 저하되는 이슈가 발생하였습니다.
const onChangeImage = async e => {
const imageFile = e.target.files[0];
const options = {
maxSizeMB: 1,
maxWidthOrHeight: 1920,
useWebWorker: true,
};
try {
const compressedFile = await imageCompression(imageFile, options);
setcommunityImage(compressedFile);
} catch (error) {
console.log(error);
}
let reader = new FileReader();
if (imageFile) {
reader.readAsDataURL(imageFile);
}
reader.onloadend = () => {
const previewImgUrl = reader.result;
if (previewImgUrl) {
setImageSrc(previewImgUrl);
}
};
};
imageCompression을 활용해 용량을 줄여 1mb이하로 줄여 받을수있게 이미지를 리사이징하였습니다.
▶️ imageCompression 활용법 공식문서 참조
https://www.npmjs.com/package/browser-image-compression
browser-image-compression
Compress images in the browser. Latest version: 2.0.0, last published: 8 months ago. Start using browser-image-compression in your project by running `npm i browser-image-compression`. There are 100 other projects in the npm registry using browser-image-co
www.npmjs.com


기존의 4.4MB사진에서 930KB로 파일크기가 줄어들었으며


서버에 저장시에도 2MB ⇒ 604.8KB로 줄어들어 저장이되어 서버의 부담을 줄일 수 있었습니다.
'React 리액트 > React 리액트' 카테고리의 다른 글
| React 전역상태관리를 리덕스에서 리코일로 바꾼이유! (1) | 2022.12.18 |
|---|---|
| React-qurey 무한스크롤 리랜더링발생 해결방안 (토큰문제) (0) | 2022.12.18 |
| react query로 무한스크롤 구현하기 (1) | 2022.12.12 |
| React 비지니스로직, UI로직 분리하기, 효율적인 폴더구조 짜기 (0) | 2022.12.05 |
| [react] props 상위컴포넌트에서 조건error (0) | 2022.11.20 |
Comments