CSR์ ๋ํ์ ์ธ ์ด๊ธฐ ๋ก๋ฉ์๋๋ฅผ ๊ฐ์ ํ๊ธฐ ์ํ ์์ ๋ค์ ์ํํด๋ณด์๋ค.
1. React.lazy์ Suspense ์ ์ฉํ๊ธฐ
const PATHS = {
main: "/main",
logIn: "/",
signUp: "/signup",
findPassword: "/find/pw",
profiles: {
detail: "/profiles/:userId",
create: "/profiles/create",
update: "/profiles/update/:userId",
},
posts: {
detail: "/posts/:postId",
create: "/posts/create",
update: "/posts/update/:postId",
},
search: "/search",
likes: "/likes/:userId",
bookmarks: "/bookmarks/:userId",
notFound: "*",
};



- DOMContentLoaded: 111ms → 81ms (27% ๊ฐ์)
- Load: 152ms → 102ms (33% ๊ฐ์)
2. ๋ฒ๋ค ์ฌ์ด์ฆ ์ค์ด๊ธฐ
lodash-es
import { debounce } from "lodash-es";
๊ธฐ์กด์ ์ฌ์ฉํ๋ lodash๋ CommonJS ๋ชจ๋ ์์คํ ์ ์ฌ์ฉํ๊ณ , lodash-es๋ ES ๋ชจ๋ ์์คํ ์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์, Vite๊ฐ์ ๋ฒ๋ค๋ฌ๊ฐ Tree Shaking์ด ๊ฐ๋ฅํด ์ฌ์ฉ๋์ง ์๋ ์ฝ๋๋ฅผ ๋ฒ๋ค์์ ์ ๊ฑฐํ์ฌ ๋น๋ ๊ฒฝ๋ํ์ ๋์์ด ๋ ์ ์๋ค๊ณ ํ๋ค.
manualChunks
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
build์, ์ด์ ๊ฐ์๊ฒฝ๊ณ ๋ฌธ๊ตฌ๊ฐ ๋จ๋๋ฐ, ๋๋ฒ์งธ ์ง์๋ก๋ build.rollupOptions.output.manualChunks ์ฌ์ฉํ๋ผ๊ณ ํ๋ค.
build: {
rollupOptions: {
output: {
manualChunks: {
vendor: ["react", "react-dom"],
firebase: [
"firebase/firestore",
"firebase/storage",
"firebase/analytics",
],
ui: [
"@radix-ui/react-alert-dialog",
"@radix-ui/react-dialog",
"@radix-ui/react-dropdown-menu",
"@radix-ui/react-label",
"@radix-ui/react-popover",
"@radix-ui/react-slot",
"@radix-ui/react-tabs",
],
lodash: ["lodash-es", "lodash-es/debounce"],
emojiPicker: ["emoji-picker-react"],
},
},
},
},
๐๐ป ํฌ๊ธฐ๊ฐ ํฐ firebase, shadui, lodash, emojipicker๋ฅผ ๋ณ๋์ ์ฒญํฌ๋ก ๋ถ๋ฆฌํ์ฌ ๋น๋ ํฌ๊ธฐ๋ฅผ ๋ถํ ํด์ฃผ์๋ค.
3. Prefetching
Prefetch๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฏธ๋ฆฌ ๋ฆฌ์์ค๋ค์ fetch๋ฅผ ํด๋๊ธฐ ๋๋ฌธ์, ๋ก๋ฉ์๊ฐ์ด ๋จ์ถ๋๋ฉด์ ์ฌ์ฉ์ ๊ฒฝํ์ ํฌ๊ฒ ํฅ์์ํฌ ์ ์๋ค.
const handleClickPostCard = async () => {
await queryClient.prefetchQuery(
queryKey: [POST, post.id],
queryFn: () => getPostByPostId(post.id || ""),
});
navigate(`/posts/${post.id}`);
};
'ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๊ฒ์๋ฌผ ์ด๋ฏธ์ง CLS ๊ฐ์ (0) | 2024.07.11 |
---|---|
Firebase ๋ถ๋ถ ๋ฌธ์ ๊ฒ์๊ธฐ๋ฅ ๊ตฌํ (0) | 2024.07.11 |
[react-query] ์ข์์ ๊ธฐ๋ฅ ์ต์ ํํ๊ธฐ (0) | 2024.07.02 |
[Firebase] ์ธ์ฆ ์ํ ์ ์ง, ์ ๊ทผ ๋ณดํธ (0) | 2024.06.27 |
[Next.js] SEO ์ต์ ํํ๊ธฐ (0) | 2024.04.29 |