Skip to content

Commit 7640eaa

Browse files
authored
Merge pull request #223 from manNomi/refactor/PopularUniversitySection
refactor : PopularUniversitySection
2 parents b67eb1e + 30062f6 commit 7640eaa

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

next.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const nextConfig = {
1313
"d1q5o8tzvz4j3d.cloudfront.net",
1414
"d23lwokhcc3r0c.cloudfront.net",
1515
],
16+
formats: ["image/avif", "image/webp"],
17+
deviceSizes: [360, 640, 768, 1024, 1280],
1618
},
1719
// 폰트 최적화 설정
1820
optimizeFonts: true,

src/app/_home/_ui/NewsSection/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export type NewsSectionProps = {
1414
const NewsSection = ({ newsList }: NewsSectionProps) => {
1515
const [visible, setVisible] = useState(false);
1616
const sectionRef = useRef<HTMLDivElement | null>(null);
17-
1817
useEffect(() => {
1918
if (!sectionRef.current) return;
2019

src/app/_home/_ui/PopularUniversitySection/index.tsx

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Image from "next/image";
22
import Link from "next/link";
3+
import { Suspense } from "react";
34

45
import { ListUniversity } from "@/types/university";
56

@@ -8,10 +9,14 @@ type PopularUniversitySectionProps = {
89
};
910

1011
const PopularUniversitySection = ({ universities }: PopularUniversitySectionProps) => {
12+
const aboveFold = universities.slice(0, 3);
13+
const belowFold = universities.slice(3);
14+
1115
return (
1216
<div className="overflow-x-auto">
1317
<div className="flex gap-2">
14-
{universities.map((university, index) => (
18+
{/* 첫 4장은 즉시 전송 – LCP 후보 */}
19+
{aboveFold.map((university, index) => (
1520
<Link key={university.id} href={`/university/${university.id}`}>
1621
<div className="relative w-[153px]">
1722
<div className="relative w-[153px]">
@@ -25,9 +30,9 @@ const PopularUniversitySection = ({ universities }: PopularUniversitySectionProp
2530
width={153}
2631
height={120}
2732
alt={`${university.koreanName || "대학교"} 배경 이미지`}
28-
priority={index < 3} // 상위 3개는 우선 로딩
29-
loading={index >= 3 ? "lazy" : "eager"}
30-
fetchPriority={index === 0 ? "high" : index < 3 ? "high" : "auto"}
33+
priority={index === 0} // 첫 카드만 LCP 후보
34+
loading={index === 0 ? "eager" : "lazy"}
35+
fetchPriority={index === 0 ? "high" : "low"}
3136
sizes="153px"
3237
unoptimized={false}
3338
/>
@@ -38,9 +43,50 @@ const PopularUniversitySection = ({ universities }: PopularUniversitySectionProp
3843
</div>
3944
</Link>
4045
))}
46+
47+
{/* 나머지는 뒤늦게 HTML 스트림으로 전송 */}
48+
{belowFold.length > 0 && (
49+
<Suspense fallback={null}>
50+
<PopularUniversitiesBelowFold universities={belowFold} />
51+
</Suspense>
52+
)}
4153
</div>
4254
</div>
4355
);
4456
};
4557

58+
const PopularUniversitiesBelowFold = ({ universities }: { universities: ListUniversity[] }) => {
59+
return (
60+
<>
61+
{universities.map((university) => (
62+
<Link key={university.id} href={`/university/${university.id}`}>
63+
<div className="relative w-[153px]">
64+
<div className="relative w-[153px]">
65+
<Image
66+
className="h-[120px] rounded-lg object-cover"
67+
src={
68+
university.backgroundImageUrl
69+
? `${process.env.NEXT_PUBLIC_IMAGE_URL}/${university.backgroundImageUrl}`
70+
: "/images/default-university.jpg"
71+
}
72+
width={153}
73+
height={120}
74+
alt={`${university.koreanName || "대학교"} 배경 이미지`}
75+
priority={false}
76+
loading="lazy"
77+
fetchPriority="low"
78+
sizes="153px"
79+
unoptimized={false}
80+
/>
81+
</div>
82+
<div className="absolute bottom-[9px] left-[10px] z-10 text-sm font-semibold leading-[160%] tracking-[0.15px] text-white">
83+
{university.koreanName}
84+
</div>
85+
</div>
86+
</Link>
87+
))}
88+
</>
89+
);
90+
};
91+
4692
export default PopularUniversitySection;

0 commit comments

Comments
 (0)