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.
문제
기존 코드는 통합된 하나의 빌드 파일을 가지기 때문에 TodoList 페이지를 로드할 때도 회원가입 폼이 로드되는 등 사용되지 않는 코드까지 한꺼번에 로드된다.
해결
페이지 별로 코드를 분할해 페이지에 필요한 코드만 로드한다.
webpack-bundle-analyzer
와cra-bundle-analyzer
를 통해 빌드 파일 시각적으로 분석Suspense
와lazy
를 통해 컴포넌트를 동적으로 import해서 코드 분할 및 지연 로딩추가
추가 의견
코드 분할로 인해 페이지마다 불필요한 코드가 로드되지는 않으나, 코드 분할 전보다 로드해야할 JavaScript 파일의 총 크기가 약간 늘어나 오히려 성능에 도움되지 않았다.
이건 코드 분할로 인해 감소되는 코드 크기보다 코드 분할로 인해 추가된 코드의 크기가 더 크기 때문이라고 생각된다.
코드가 크지 않다면 코드 분할을 적용하지 않는 것이 더 성능에 좋을 것으로 판단된다.
조금이라도 성능을 좋게 하려면 이 코드 분할은 하지 않는 것이 낫지만, 총 코드 크기가 크게 차이나지 않고 코드 분할에 대한 예제를 남기고자 merge한다.