기본 정보

208255839-98b7914d-9c39-4ef3-a24d-31aa5d2df9a1.gif

깃허브 :

깃허브 링크

기술문서 모음 :

XOXO wiki

기술 스택 :

TypeScript, React, Sass, Naver Cloud Platform (NCP)

담당 :

프론트엔드

개발 기간 :

6주


프로젝트 소개


성과

이미지 캐러셀 최적화

관련문서 :

XOXO한 클라이언트 이미지 최적화

Image Optimizer를 통한 반응형 최적화를 진행해보자!

[useEffect를 활용한 lazy loading 코드]

useEffect(() => {
    if (page + 2 < imageStatus.length && imageStatus[page + 2].isLq === true) {
      setImageStatus((imageStatus) => {
        const newImageStatus = [...imageStatus]
        const target = newImageStatus[page + 2]
        target.isLq = false
        target.src = getPostingThumbUrl(target.url!)
        newImageStatus[page + 2] = target
        return newImageStatus
      })
    }
  }, [page])

[화면크기를 감지하고 그에 맞는 이미지 URL을 생성하는 코드]

export const getthumbUrl = (url: string) => {
  return `${url}${getQueryString(true)}`
}
export const getoriginalUrl = (url: string) => {
  return `${url}${getQueryString(false)}`
}
const getQueryString = (isLq: boolean) => {
  const windowWidth = window.innerWidth
  const size = isLq ? getThumbSize(windowWidth) : getOriginalSize(windowWidth)
  return `?type=m&w=${size}&h=${size}`
}
const getOriginalSize = (widdowWidth: number) => {
  const level = Math.floor(widdowWidth / 100)
  if (level >= 5) return 500
  if (level >= 4) return 400
  return 300
}
const getThumbSize = (widdowWidth: number) => {
  const level = Math.floor(widdowWidth / 100)
  if (level >= 5) return 50
  if (level >= 4) return 40
  return 30
}

이미지 픽셀화 기능 개선

그림1.png