-
Notifications
You must be signed in to change notification settings - Fork 53
[3팀 여진석] Chapter 4-1 성능 최적화 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
realstone2
wants to merge
20
commits into
hanghae-plus:main
Choose a base branch
from
realstone2:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 준일님짱짱맨 내용을 추가함
- 새로운 ClientRouter와 ServerRouter 구조 추가 - 기존 Router.js 파일 삭제 - 라우터 관련 파일들 구조 개선 - main-server.js에서 사용되지 않는 import 제거
- 서버 설정 파일 개선 - 새로운 서버 데이터 처리 로직 추가 - Node.js 환경용 mock 핸들러 추가
- 상품 API 로직 개선 - 상품 서비스 로직 개선 - 홈페이지 및 상품 상세 페이지 컴포넌트 개선
- HTML 파일 개선 - 스토리지 생성 로직 개선 - 메인 진입점 파일 개선 - Mock 핸들러 개선 - PR 문서 업데이트
- 상품 상세 페이지에서 관련 상품 로드 기능 추가 - 관련 상품을 스토어에 저장하는 로직 추가 - 서버 데이터에서 관련 상품을 가져오는 기능 추가
- 서버 설정 및 라우팅 로직 개선 - 상품 API 로직 개선 - 서버 라우터 및 데이터 처리 로직 개선
- Mock 핸들러 로직 개선 - 홈페이지 컴포넌트 기능 개선
- create withSSR higher-order component for SSR functionality - support server data injection and head rendering - enable page rendering with server-side data - fix unused variable linting errors
- add ServerRouter class for SSR routing functionality - implement route matching and parameter extraction - add main-server.js for server-side page rendering - export withSSR from router index for easy access
- integrate withSSR HOC in HomePage and ProductDetailPage - add server-side data fetching for product details - implement head rendering for SEO optimization - support both SSR and client-side rendering modes
- integrate getServerData for SSR data injection - support both server and client-side data loading - optimize data fetching for server-side rendering
- add server-side rendering middleware - configure static file serving for production - integrate MSW for API mocking in server environment
- 정적 파일 서빙 경로를 변경하여 프로덕션 환경에 맞춤 - 서버 사이드 렌더링을 위한 메인 서버 모듈 경로 수정 - 상품 API의 base URL 설정을 환경에 따라 동적으로 변경
- prerender.js 파일을 추가하여 정적 사이트 생성을 위한 로직 구현 - 빌드 후 생성된 파일을 기반으로 홈페이지 및 상품 페이지 생성 기능 추가 - 404 페이지 및 정적 자산 복사 기능 포함 - package.json에서 SSG 빌드 스크립트 수정
- prerender.js에서 SSG 출력 디렉토리를 'dist/vanilla'에서 'dist/vanilla-ssg'로 수정 - package.json의 SSG 프리뷰 스크립트 경로를 업데이트하여 일관성 유지
- Router 모듈의 파일 이름을 대문자에서 소문자로 변경하여 일관성 유지
- prerender.js에서 SSG 결과물을 루트 dist 폴더로 복사하는 로직 추가 - package.json의 SSG 프리뷰 스크립트 경로를 루트 dist 폴더에 맞게 수정하여 일관성 유지
- SSG 빌드 스크립트에서 mockServiceWorker.js 파일을 dist/vanilla 디렉토리로 복사하는 로직 추가하여 서비스 워커 지원 개선
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
과제 체크포인트
배포 링크
기본과제 https://realstone2.github.io/front_6th_chapter4-1/vanilla/
기본과제 (Vanilla SSR & SSG)
Express SSR 서버
<!--app-html-->,<!--app-head-->)서버 사이드 렌더링
클라이언트 Hydration
window.__INITIAL_DATA__스크립트 주입Static Site Generation
심화과제 (React SSR & SSG)
React SSR
renderToString서버 렌더링React Hydration
React Static Site Generation
구현 과정 돌아보기
가장 어려웠던 부분과 해결 과정
SSR Router
SSR 라우터 분기 방식을 단순히 아래처럼 만들고 router를 서버나 클라이언트에서 사용하려고 했더니 문제가 발생하였다.
하나씩 실행할 때는 문제가 없었는데, e2e테스트를 동시에 돌리는 경우에 문제가 발생하였다.
고민하다보니까 서버에서 router 인스턴스를 전역으로 한개를 사용하면서 query, route의 값이 계속 바뀌는게 문제였다.
과거에도 SSR에서 store를 사용했다가 문제를 겪었던 기억이 경험이 있었는데, router도 마찬가지라는 것을 간과했다.
기존에 router를 import해서 가져오던 방식을 nextJS가 route값을 params로 받는 방식이 떠올라서 route를 전달받는 방식으로 수정하였다.
ssr html 만드는 과정
위에서 route전달 하는 방식으로 수정한다고 했는데, 이러다보니까 기존 page 인터페이스형식도 변경이 필요하다고 느껴졌다.
기존에는 route를 등록할 때 getSSRData를 받아오고, store를 설정해주는 등의 작업을 거쳤는데, 이것도 문제였다.
express에서 주소를 요청받으면 그 때 서버데이터를 새로 생성하고 store에 넣어주도록 수정하였다.
해당 방식을 좀 일관성있는 인터페이스를 구성하고자 아래 인터페이스를 구성하였다.
renderPage 함수로 생성할 때 마다 새롭게 데이터가 셋팅되도록 수정하였다.
구현하면서 새롭게 알게 된 개념
SSR과 client에서의 hydration
nextjs를 page라우터를 사용할 때 서버에서 한번 랜더링 클라이언트에서 한번 랜더링 된다라는 개념이 왜그런지 잘 이해가 안되었는데, 이번에 직접구성하다보니 이해가 되었다.
결국 같은 DomTree를 구성하게 되고, client에서는 event등록 css등의 hydration 과정을 거치게 된다.
성능 최적화 관점에서의 인사이트
학습 갈무리
Q1. 현재 구현한 SSR/SSG 아키텍처에서 확장성을 고려할 때 어떤 부분을 개선하시겠습니까?
Q2. Express 서버 대신 다른 런타임(Cloudflare Workers, Vercel Edge Functions 등)을 사용한다면 어떤 점을 수정해야 할까요?
람다를 사용해서 server를 구성한다면 express처럼 항상 서버가 띄워져있는 상황보다 서버비용을 줄일 수 있다.
Q3. 현재 구현에서 성능 병목이 될 수 있는 지점은 어디이고, 어떻게 개선하시겠습니까?
Q4. 1000개 이상의 상품 페이지를 SSG로 생성할 때 고려해야 할 사항은 무엇입니까?
상품이 많을수록 빌드가 너무 오랜 시간이 걸리는 것이 문제다.
Q5. Hydration 과정에서 사용자가 느낄 수 있는 UX 이슈는 무엇이고, 어떻게 개선할 수 있을까요?
hydration이 되기전까지는 이벤트가 발생하지 않는 문제가 있다.
로딩 UI를 노출시키거나, event를 등록하는 js파일을 가장 우선순위로 호출하면 어느정도는 해결되지 않을까싶다.
Q6. 이번 과제에서 학습한 내용을 실제 프로덕션 환경에 적용할 때 추가로 고려해야 할 사항은?
SSR의 경우는 서버 모니터링 필요.
SSG의 경우는 얼마나 자주 빌드를 해줄 것인지 정책을 정해야한다.
Q7. Next.js 같은 프레임워크 대신 직접 구현한 SSR/SSG의 장단점은 무엇인가요?
학습적으로 원하는 기능을 필요에 따라 넣을 수 있다.
불필요하게 지원해주는 nextjs기능을 사용하지 않아도 된다.
vercel에 종속적이지 않고 사용하는 클라우드에 접목시키기 쉽다.
Q8. Next.js 를 이용하여 SSG 방식으로 배포하려면 어떻게 해야 좋을까요?
코드 품질 향상
자랑하고 싶은 구현
page 컴포넌트 선언하는 부분이 깔끔한 인터페이스라고 생각되었습니다.
개선하고 싶은 부분
캐싱전략, 서버컴포넌트 방식 도입 등을 도입시켜보고 싶습니다.
지금은 SSG를 직접 빌드해야지만 작동하지만 캐싱시간을 정해놓는 인터페이스를 구현하고 싶습ㄴ디ㅏ.
리팩토링 계획
학습 연계
다음 학습 목표
실무 적용 계획
개인 블로그를 만들 때 해당 내용을 생각하면서 구성할 수 있을 것 같습니다.
리뷰 받고 싶은 내용
페이지 이동시에 매번 내용을 넣어주면서 교체시켜줘야되나도 생각해봤지만, 이게 맞나? 싶은 것 같습니다.
이 문제를 어떤식으로 해결할 수 있을까요?