Ver3.0 ๐ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๊ตฌํํ๋ ๋ฌดํ ์คํฌ๋กค: ์ฌ์ฉ์ ๊ฒฝํ์ ๊ทน๋ํํ๋ ์ค์ ๊ฐ์ด๋

๐ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๊ตฌํํ๋ ๋ฌดํ ์คํฌ๋กค: ์ฌ์ฉ์ ๊ฒฝํ์ ๊ทน๋ํํ๋ ์ค์ ๊ฐ์ด๋
์คํฌ๋กค๋ง์ผ๋ก ๋์์ด ํผ์ณ์ง๋ ์ฝํ ์ธ ์ ๋ง๋ฒ, ๊ทธ ๋น๋ฐ์ ํํค์ณ๋ณด์! ๐โจ
๐ฏ ๋ฌดํ ์คํฌ๋กค, ์ ์ด๋ ๊ฒ ์ค์ํ ๊น?
์ฌ๋ฌ๋ถ, ์ธ์คํ๊ทธ๋จ์ด๋ ํ์ด์ค๋ถ์ ์ธ ๋ '๋ค์ ํ์ด์ง' ๋ฒํผ์ ๋๋ฌ๋ณธ ์ ์๋์? ์๋ง ์์ ๊ฑฐ์์. ๊ทธ๋ฅ ์คํฌ๋กค๋ง ๋ด๋ฆฌ๋ฉด ์๋ก์ด ์ฝํ
์ธ ๊ฐ ๋์์ด ๋ํ๋์ฃ . ์ด๊ฒ ๋ฐ๋ก ๋ฌดํ ์คํฌ๋กค(Infinite Scroll)์ด์์! ๐ข
๋ฌดํ ์คํฌ๋กค์ ๋จ์ํ 'ํธ๋ฆฌํ ๊ธฐ๋ฅ'์ ๋์ด์ ํ๋ ์น ๊ฐ๋ฐ์ ํต์ฌ UX ํจํด์ด ๋์์ด์. ์ฌ์ฉ์๋ค์ ํ์ด์ง๋ค์ด์
๋ฒํผ์ ํด๋ฆญํ๋ ๊ฒ๋ณด๋ค ์์ฐ์ค๋ฝ๊ฒ ์คํฌ๋กคํ๋ ๊ฑธ ํจ์ฌ ์ ํธํ๊ฑฐ๋ ์. ์ค์ ๋ก ์ฐ๊ตฌ์ ๋ฐ๋ฅด๋ฉด ๋ฌดํ ์คํฌ๋กค์ ์ ์ฉํ ์ฌ์ดํธ๋ ์ฌ์ฉ์ ์ฒด๋ฅ ์๊ฐ์ด ํ๊ท 30% ์ด์ ์ฆ๊ฐํ๋ค๊ณ ํด์! ๐
ํ์ง๋ง ๋ฌดํ ์คํฌ๋กค์ ์๋ชป ๊ตฌํํ๋ฉด ์คํ๋ ค ๋
์ด ๋ ์ ์์ด์. ํ์ด์ง๊ฐ ๋๋ ค์ง๊ฑฐ๋, ๋ฉ๋ชจ๋ฆฌ๊ฐ ํฐ์ง๊ฑฐ๋, ์ฌ์ฉ์๊ฐ ์ํ๋ ์ฝํ
์ธ ๋ฅผ ์ฐพ์ง ๋ชปํ๋ ์ํฉ์ด ๋ฐ์ํ ์ ์์ฃ . ๊ทธ๋์ ์ค๋์ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ฌดํ ์คํฌ๋กค์ ์ ๋๋ก ๊ตฌํํ๋ ๋ฐฉ๋ฒ๊ณผ UX๋ฅผ ๊ฐ์ ํ๋ ์ค์ ํ๋ค์ ์น๊ตฌ์ฒ๋ผ ํธํ๊ฒ ์๋ ค๋๋ฆด๊ฒ์! ๐ค
๐ ๋ฌดํ ์คํฌ๋กค์ ํต์ฌ ์๋ฆฌ ์ดํดํ๊ธฐ
๋ฌดํ ์คํฌ๋กค์ ๊ตฌํํ๊ธฐ ์ ์, ๋จผ์ ๊ทธ ์๋ ์๋ฆฌ๋ฅผ ์ดํดํด์ผ ํด์. ์ฌ์ค ๊ฐ๋
์ ์ ๋ง ๊ฐ๋จํด์! ๐
๊ธฐ๋ณธ ์๋ฆฌ๋ ์ด๋์:
1๏ธโฃ ์ฌ์ฉ์๊ฐ ํ์ด์ง๋ฅผ ์คํฌ๋กคํด์
2๏ธโฃ ์คํฌ๋กค ์์น๊ฐ ํ์ด์ง ํ๋จ์ ๊ฐ๊น์์ง๋ฉด ๊ฐ์งํด์
3๏ธโฃ ์๋ฒ์ ์๋ก์ด ๋ฐ์ดํฐ๋ฅผ ์์ฒญํด์
4๏ธโฃ ๋ฐ์์จ ๋ฐ์ดํฐ๋ฅผ ํ์ด์ง ํ๋จ์ ์ถ๊ฐํด์
5๏ธโฃ 1๋ฒ์ผ๋ก ๋์๊ฐ์ ๋ฐ๋ณตํด์! ๐
์ด ๊ณผ์ ์์ ๊ฐ์ฅ ์ค์ํ ๊ฑด "์ธ์ ์๋ก์ด ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ฌ ๊ฒ์ธ๊ฐ"๋ฅผ ๊ฒฐ์ ํ๋ ๊ฑฐ์์. ๋๋ฌด ์ผ์ฐ ๋ถ๋ฌ์ค๋ฉด ๋ถํ์ํ ์์ฒญ์ด ๋ง์์ง๊ณ , ๋๋ฌด ๋ฆ๊ฒ ๋ถ๋ฌ์ค๋ฉด ์ฌ์ฉ์๊ฐ ๊ธฐ๋ค๋ ค์ผ ํ์ฃ .
โ๏ธ ๋ฌดํ ์คํฌ๋กค ๊ตฌํ ๋ฐฉ๋ฒ 3๊ฐ์ง
์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ฌดํ ์คํฌ๋กค์ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ํฌ๊ฒ ์ธ ๊ฐ์ง๊ฐ ์์ด์. ๊ฐ๊ฐ ์ฅ๋จ์ ์ด ์์ผ๋ ํ๋ก์ ํธ ์ํฉ์ ๋ง๊ฒ ์ ํํ๋ฉด ๋ผ์! ๐จ
๐ Scroll Event ํ์ฉํ๊ธฐ (์ ํต์ ๋ฐฉ๋ฒ)
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ด๊ณ ์ง๊ด์ ์ธ ๋ฐฉ๋ฒ์ด์์. window์ scroll ์ด๋ฒคํธ๋ฅผ ๊ฐ์งํด์ ์คํฌ๋กค ์์น๋ฅผ ๊ณ์ฐํ๋ ๊ฑฐ์ฃ .
์ฅ์ :
โ
์ดํดํ๊ธฐ ์ฝ๊ณ ๊ตฌํ์ด ๊ฐ๋จํด์
โ
๋ธ๋ผ์ฐ์ ํธํ์ฑ์ด ๋ฐ์ด๋์
โ
์ธ๋ฐํ ์ ์ด๊ฐ ๊ฐ๋ฅํด์
๋จ์ :
โ ์คํฌ๋กค ์ด๋ฒคํธ๊ฐ ๋๋ฌด ์์ฃผ ๋ฐ์ํด์ ์ฑ๋ฅ ์ด์๊ฐ ์์ ์ ์์ด์
โ ์ฐ๋กํ๋ง(throttling)์ด๋ ๋๋ฐ์ด์ฑ(debouncing) ์ฒ๋ฆฌ๊ฐ ํ์ํด์
// ๊ธฐ๋ณธ์ ์ธ ์คํฌ๋กค ์ด๋ฒคํธ ๊ตฌํ
let isLoading = false;
let currentPage = 1;
window.addEventListener('scroll', () => {
// ์คํฌ๋กค ์์น ๊ณ์ฐ
const scrollTop = window.scrollY;
const windowHeight = window.innerHeight;
const documentHeight = document.documentElement.scrollHeight;
// ํ๋จ์์ 300px ์ง์ ์ ๋๋ฌํ๋์ง ํ์ธ
if (scrollTop + windowHeight >= documentHeight - 300) {
if (!isLoading) {
loadMoreContent();
}
}
});
async function loadMoreContent() {
isLoading = true;
try {
const response = await fetch(`/api/content?page=${currentPage}`);
const data = await response.json();
// ์ฝํ
์ธ ์ถ๊ฐ
appendContent(data);
currentPage++;
} catch (error) {
console.error('๋ฐ์ดํฐ ๋ก๋ฉ ์คํจ:', error);
} finally {
isLoading = false;
}
}
์คํฌ๋กค ์ด๋ฒคํธ๋ ์ด๋น ์์ญ ๋ฒ์ฉ ๋ฐ์ํ ์ ์์ด์! ๋ฐ๋์ ์ฐ๋กํ๋ง์ ์ ์ฉํด์ ์ฑ๋ฅ์ ์ต์ ํํด์ผ ํด์.
๐ฏ Intersection Observer API ํ์ฉํ๊ธฐ (๊ถ์ฅ ๋ฐฉ๋ฒ)
ํ๋์ ์ด๊ณ ์ฑ๋ฅ์ด ๋ฐ์ด๋ ๋ฐฉ๋ฒ์ด์์. ํน์ ์์๊ฐ ๋ทฐํฌํธ์ ๋ค์ด์๋์ง๋ฅผ ๊ฐ์งํ๋ ๋ธ๋ผ์ฐ์ API๋ฅผ ์ฌ์ฉํด์.
์ฅ์ :
โ
์ฑ๋ฅ์ด ๋งค์ฐ ๋ฐ์ด๋์ (๋ธ๋ผ์ฐ์ ๊ฐ ์ต์ ํํด์ค์)
โ
์ฐ๋กํ๋ง์ด ํ์ ์์ด์
โ
์ฝ๋๊ฐ ๊น๋ํ๊ณ ๊ด๋ฆฌํ๊ธฐ ์ฌ์์
โ
๋น๋๊ธฐ๋ก ์๋ํด์ ๋ฉ์ธ ์ค๋ ๋๋ฅผ ์ฐจ๋จํ์ง ์์์
๋จ์ :
โ IE์์๋ ํด๋ฆฌํ์ด ํ์ํด์ (ํ์ง๋ง ์์ฆ์ ํฐ ๋ฌธ์ ๊ฐ ์๋์ฃ !)
// Intersection Observer๋ฅผ ํ์ฉํ ๋ฌดํ ์คํฌ๋กค
let currentPage = 1;
let isLoading = false;
// ๊ฐ์ํ ์์ ์์ฑ (ํ์ด์ง ํ๋จ์ ๋ฐฐ์น)
const sentinel = document.createElement('div');
sentinel.id = 'sentinel';
document.querySelector('#content-container').appendChild(sentinel);
// Observer ์ค์
const observer = new IntersectionObserver(
(entries) => {
entries.forEach(entry => {
// sentinel์ด ํ๋ฉด์ ๋ณด์ด๋ฉด ๋ฐ์ดํฐ ๋ก๋
if (entry.isIntersecting && !isLoading) {
loadMoreContent();
}
});
},
{
// ํ๋จ์์ 200px ์ ์ ํธ๋ฆฌ๊ฑฐ
rootMargin: '200px',
threshold: 0
}
);
// ๊ฐ์ ์์
observer.observe(sentinel);
async function loadMoreContent() {
isLoading = true;
// ๋ก๋ฉ ์ธ๋์ผ์ดํฐ ํ์
showLoadingIndicator();
try {
const response = await fetch(`/api/content?page=${currentPage}`);
const data = await response.json();
if (data.items.length > 0) {
appendContent(data.items);
currentPage++;
// sentinel์ ์๋ก์ด ์ฝํ
์ธ ์๋๋ก ์ด๋
const container = document.querySelector('#content-container');
container.appendChild(sentinel);
} else {
// ๋ ์ด์ ๋ฐ์ดํฐ๊ฐ ์์ผ๋ฉด ๊ฐ์ ์ค๋จ
observer.unobserve(sentinel);
showEndMessage();
}
} catch (error) {
console.error('๋ฐ์ดํฐ ๋ก๋ฉ ์คํจ:', error);
showErrorMessage();
} finally {
hideLoadingIndicator();
isLoading = false;
}
}
function appendContent(items) {
const container = document.querySelector('#content-container');
items.forEach(item => {
const element = document.createElement('div');
element.className = 'content-item';
element.innerHTML = `
<h3>${item.title}</h3>
<p>${item.description}</p>
`;
container.insertBefore(element, sentinel);
});
}
Intersection Observer๋ ๋ฌดํ ์คํฌ๋กค๋ฟ๋ง ์๋๋ผ ์ด๋ฏธ์ง ๋ ์ด์ง ๋ก๋ฉ, ์ ๋๋ฉ์ด์ ํธ๋ฆฌ๊ฑฐ ๋ฑ ๋ค์ํ ๊ณณ์ ํ์ฉํ ์ ์์ด์. ํ ๋ฒ ์ตํ๋๋ฉด ์ ๋ง ์ ์ฉํด์!
๐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ฉํ๊ธฐ (๋น ๋ฅธ ๊ตฌํ)
์ง์ ๊ตฌํํ๊ธฐ ๋ถ๋ด์ค๋ฝ๋ค๋ฉด ๊ฒ์ฆ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๋ ์ข์ ์ ํ์ด์์.
์ถ์ฒ ๋ผ์ด๋ธ๋ฌ๋ฆฌ:
๐น react-infinite-scroll-component - React ํ๋ก์ ํธ์ ์ต์ ํ
๐น vue-infinite-scroll - Vue.js ํ๋ก์ ํธ์ฉ
๐น infinite-scroll (by Metafizzy) - ๋ฐ๋๋ผ JS์ฉ, ๊ฐ๋ณ๊ณ ๊ฐ๋ ฅํด์
์ฅ์ :
โ
๋น ๋ฅด๊ฒ ๊ตฌํํ ์ ์์ด์
โ
๋ฒ๊ทธ๊ฐ ์ ๊ณ ์์ ์ ์ด์์
โ
๋ค์ํ ์ต์
๊ณผ ์ปค์คํฐ๋ง์ด์ง์ด ๊ฐ๋ฅํด์
๋จ์ :
โ ๋ฒ๋ค ํฌ๊ธฐ๊ฐ ์ฆ๊ฐํด์
โ ์ธ๋ฐํ ์ ์ด๊ฐ ์ด๋ ค์ธ ์ ์์ด์
โ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์กด์ฑ์ด ์๊ฒจ์
// react-infinite-scroll-component ์์
import InfiniteScroll from 'react-infinite-scroll-component';
function ContentList() {
const [items, setItems] = useState([]);
const [hasMore, setHasMore] = useState(true);
const [page, setPage] = useState(1);
const fetchMoreData = async () => {
try {
const response = await fetch(`/api/content?page=${page}`);
const newItems = await response.json();
if (newItems.length === 0) {
setHasMore(false);
return;
}
setItems([...items, ...newItems]);
setPage(page + 1);
} catch (error) {
console.error('๋ฐ์ดํฐ ๋ก๋ฉ ์คํจ:', error);
}
};
return (
<InfiniteScroll
dataLength={items.length}
next={fetchMoreData}
hasMore={hasMore}
loader={<h4>๋ก๋ฉ ์ค...</h4>}
endMessage={<p>๋ชจ๋ ์ฝํ
์ธ ๋ฅผ ํ์ธํ์ด์! ๐</p>}
>
{items.map((item, index) => (
<div key={index} className="content-item">
<h3>{item.title}</h3>
<p>{item.description}</p>
</div>
))}
</InfiniteScroll>
);
}
๐ ์ฑ๋ฅ ์ต์ ํ: ๋ฌดํ ์คํฌ๋กค์ ๋น ๋ฅด๊ฒ ๋ง๋๋ ๋น๋ฒ
๋ฌดํ ์คํฌ๋กค์ ๊ตฌํํ๋ค๊ณ ๋์ด ์๋์์! ์ฑ๋ฅ ์ต์ ํ๋ฅผ ํ์ง ์์ผ๋ฉด ํ์ด์ง๊ฐ ์ ์ ๋๋ ค์ง๊ณ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ก์๋จน๊ฒ ๋ผ์. ์ค์ ์์ ๋ฐ๋ก ์ ์ฉํ ์ ์๋ ์ต์ ํ ๊ธฐ๋ฒ๋ค์ ์๋ ค๋๋ฆด๊ฒ์! ๐ช
1๏ธโฃ ๊ฐ์ ์คํฌ๋กค๋ง (Virtual Scrolling) ๊ตฌํํ๊ธฐ
์์ฒ ๊ฐ์ ์์ดํ
์ ๋ชจ๋ DOM์ ๋ ๋๋งํ๋ฉด ๋ธ๋ผ์ฐ์ ๊ฐ ๋ฒ๊ฑฐ์ํด์. ๊ฐ์ ์คํฌ๋กค๋ง์ ํ๋ฉด์ ๋ณด์ด๋ ์์ดํ
๋ง ๋ ๋๋งํ๋ ๊ธฐ๋ฒ์ด์์.
์๋ ์๋ฆฌ:
โข ์ ์ฒด ์ฝํ
์ธ ๋์ด๋ฅผ ๊ณ์ฐํด์ ์คํฌ๋กค๋ฐ ํฌ๊ธฐ๋ฅผ ์ ์งํด์
โข ํ์ฌ ์คํฌ๋กค ์์น์์ ๋ณด์ด๋ ์์ดํ
๋ง DOM์ ๋ ๋๋งํด์
โข ์คํฌ๋กคํ๋ฉด ๋ณด์ด์ง ์๋ ์์ดํ
์ ์ ๊ฑฐํ๊ณ ์๋ก์ด ์์ดํ
์ ์ถ๊ฐํด์
class VirtualScroller {
constructor(container, itemHeight, totalItems) {
this.container = container;
this.itemHeight = itemHeight;
this.totalItems = totalItems;
this.visibleItems = Math.ceil(container.clientHeight / itemHeight) + 2;
this.startIndex = 0;
this.init();
}
init() {
// ์ ์ฒด ๋์ด๋ฅผ ๊ฐ์ง ์คํ์ด์ ์์ฑ
this.spacer = document.createElement('div');
this.spacer.style.height = `${this.totalItems * this.itemHeight}px`;
this.container.appendChild(this.spacer);
// ์ค์ ์ฝํ
์ธ ์ปจํ
์ด๋
this.content = document.createElement('div');
this.content.style.position = 'absolute';
this.content.style.top = '0';
this.content.style.width = '100%';
this.container.appendChild(this.content);
// ์คํฌ๋กค ์ด๋ฒคํธ ๋ฆฌ์ค๋
this.container.addEventListener('scroll', () => this.onScroll());
// ์ด๊ธฐ ๋ ๋๋ง
this.render();
}
onScroll() {
const scrollTop = this.container.scrollTop;
const newStartIndex = Math.floor(scrollTop / this.itemHeight);
if (newStartIndex !== this.startIndex) {
this.startIndex = newStartIndex;
this.render();
}
}
render() {
const endIndex = Math.min(
this.startIndex + this.visibleItems,
this.totalItems
);
// ์ฝํ
์ธ ์์น ์กฐ์
this.content.style.transform =
`translateY(${this.startIndex * this.itemHeight}px)`;
// ๋ณด์ด๋ ์์ดํ
๋ง ๋ ๋๋ง
this.content.innerHTML = '';
for (let i = this.startIndex; i < endIndex; i++) {
const item = this.createItem(i);
this.content.appendChild(item);
}
}
createItem(index) {
const item = document.createElement('div');
item.className = 'virtual-item';
item.style.height = `${this.itemHeight}px`;
item.textContent = `์์ดํ
${index + 1}`;
return item;
}
}
// ์ฌ์ฉ ์์
const container = document.querySelector('#scroll-container');
const scroller = new VirtualScroller(container, 100, 10000);
2๏ธโฃ ์ด๋ฏธ์ง ๋ ์ด์ง ๋ก๋ฉ (Lazy Loading) ์ ์ฉํ๊ธฐ
๋ฌดํ ์คํฌ๋กค์์ ์ด๋ฏธ์ง๋ ์ฑ๋ฅ์ ์ต๋ ์ ์ด์์! ๋ชจ๋ ์ด๋ฏธ์ง๋ฅผ ํ ๋ฒ์ ๋ก๋ํ๋ฉด ๋คํธ์ํฌ์ ๋ฉ๋ชจ๋ฆฌ๊ฐ ํญ๋ฐํด์. ๐ฅ
๋ค์ดํฐ๋ธ ๋ ์ด์ง ๋ก๋ฉ (๊ฐ์ฅ ๊ฐ๋จ):
// HTML์์ loading ์์ฑ๋ง ์ถ๊ฐํ๋ฉด ๋!
<img src="image.jpg" loading="lazy" alt="์ค๋ช
">
// ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋์ ์์ฑ ์
function createImageElement(src, alt) {
const img = document.createElement('img');
img.src = src;
img.alt = alt;
img.loading = 'lazy';
return img;
}
Intersection Observer๋ฅผ ํ์ฉํ ์ปค์คํ ๋ ์ด์ง ๋ก๋ฉ:
class LazyImageLoader {
constructor() {
this.images = document.querySelectorAll('img[data-src]');
this.observer = new IntersectionObserver(
(entries) => this.handleIntersection(entries),
{
rootMargin: '50px',
threshold: 0.01
}
);
this.observe();
}
observe() {
this.images.forEach(img => this.observer.observe(img));
}
handleIntersection(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
this.loadImage(img);
this.observer.unobserve(img);
}
});
}
loadImage(img) {
const src = img.getAttribute('data-src');
// ์ ํด์๋ ํ๋ ์ด์คํ๋ ํ์
if (img.hasAttribute('data-placeholder')) {
img.src = img.getAttribute('data-placeholder');
}
// ์ค์ ์ด๋ฏธ์ง ๋ก๋
const tempImg = new Image();
tempImg.onload = () => {
img.src = src;
img.classList.add('loaded');
};
tempImg.onerror = () => {
img.src = '/images/error-placeholder.jpg';
img.classList.add('error');
};
tempImg.src = src;
}
}
// ์ฌ์ฉ
const lazyLoader = new LazyImageLoader();
1. ์๋ฒ์์ ์๋ณธ ์ด๋ฏธ์ง์ ์ด์ํ ๋ฒ์ (10x10px ์ ๋)์ ์์ฑํด์
2. ์ด ์์ ์ด๋ฏธ์ง๋ฅผ base64๋ก ์ธ์ฝ๋ฉํด์ HTML์ ์ง์ ์ฝ์ ํด์
3. CSS๋ก ๋ธ๋ฌ ํจ๊ณผ๋ฅผ ์ ์ฉํด์
4. ์ค์ ์ด๋ฏธ์ง๊ฐ ๋ก๋๋๋ฉด ๋ธ๋ฌ๋ฅผ ์ ๊ฑฐํ๊ณ ๊ต์ฒดํด์
3๏ธโฃ ๋ฐ์ดํฐ ํ์นญ ์ต์ ํํ๊ธฐ
์๋ฒ ์์ฒญ์ ํจ์จ์ ์ผ๋ก ๊ด๋ฆฌํ๋ ๊ฒ๋ ์ค์ํด์! ๐
class DataFetcher {
constructor(apiUrl, pageSize = 20) {
this.apiUrl = apiUrl;
this.pageSize = pageSize;
this.cache = new Map();
this.pendingRequests = new Map();
}
async fetchPage(page) {
// ์บ์ ํ์ธ
if (this.cache.has(page)) {
return this.cache.get(page);
}
// ์ด๋ฏธ ์์ฒญ ์ค์ธ์ง ํ์ธ (์ค๋ณต ์์ฒญ ๋ฐฉ์ง)
if (this.pendingRequests.has(page)) {
return this.pendingRequests.get(page);
}
// ์๋ก์ด ์์ฒญ
const requestPromise = this.makeRequest(page);
this.pendingRequests.set(page, requestPromise);
try {
const data = await requestPromise;
// ์บ์์ ์ ์ฅ (์ต๋ 10ํ์ด์ง๊น์ง๋ง)
if (this.cache.size >= 10) {
const firstKey = this.cache.keys().next().value;
this.cache.delete(firstKey);
}
this.cache.set(page, data);
return data;
} finally {
this.pendingRequests.delete(page);
}
}
async makeRequest(page) {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000);
try {
const response = await fetch(
`${this.apiUrl}?page=${page}&size=${this.pageSize}`,
{
signal: controller.signal,
headers: {
'Content-Type': 'application/json'
}
}
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
if (error.name === 'AbortError') {
throw new Error('์์ฒญ ์๊ฐ ์ด๊ณผ');
}
throw error;
} finally {
clearTimeout(timeoutId);
}
}
// ๋ค์ ํ์ด์ง ๋ฏธ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ (ํ๋ฆฌํ์นญ)
prefetchNextPage(currentPage) {
const nextPage = currentPage + 1;
if (!this.cache.has(nextPage) && !this.pendingRequests.has(nextPage)) {
this.fetchPage(nextPage).catch(() => {
// ํ๋ฆฌํ์นญ ์คํจ๋ ์กฐ์ฉํ ๋ฌด์
});
}
}
clearCache() {
this.cache.clear();
}
}
// ์ฌ์ฉ ์์
const fetcher = new DataFetcher('/api/content', 20);
async function loadContent(page) {
try {
const data = await fetcher.fetchPage(page);
// ๋ค์ ํ์ด์ง ๋ฏธ๋ฆฌ ๋ก๋
fetcher.prefetchNextPage(page);
return data;
} catch (error) {
console.error('๋ฐ์ดํฐ ๋ก๋ฉ ์คํจ:', error);
throw error;
}
}
โข ํ๋ฆฌํ์นญ์ผ๋ก ์ฒด๊ฐ ๋ก๋ฉ ์๊ฐ 70% ๋จ์ถ
โข ํ์์์ ์ฒ๋ฆฌ๋ก ๋ฌดํ ๋๊ธฐ ๋ฐฉ์ง
โข ์ค๋ณต ์์ฒญ ๋ฐฉ์ง๋ก ๋คํธ์ํฌ ํธ๋ํฝ ์ต์ ํ
4๏ธโฃ ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ: DOM ์์ ์ ๋ฆฌํ๊ธฐ
๋ฌดํ ์คํฌ๋กค์ ๊ฐ์ฅ ํฐ ๋ฌธ์ ๋ DOM ์์๊ฐ ๊ณ์ ์์ธ๋ค๋ ๊ฑฐ์์. ์์ฒ ๊ฐ์ ์์๊ฐ ์์ด๋ฉด ๋ธ๋ผ์ฐ์ ๊ฐ ๋๋ ค์ ธ์! ๐ฐ
class InfiniteScrollManager {
constructor(container, maxItems = 100) {
this.container = container;
this.maxItems = maxItems;
this.items = [];
}
addItems(newItems) {
newItems.forEach(item => {
const element = this.createItemElement(item);
this.container.appendChild(element);
this.items.push(element);
});
// ์ต๋ ๊ฐ์ ์ด๊ณผ ์ ์ค๋๋ ์์ดํ
์ ๊ฑฐ
this.cleanup();
}
cleanup() {
if (this.items.length > this.maxItems) {
const removeCount = this.items.length - this.maxItems;
for (let i = 0; i < removeCount; i++) {
const item = this.items.shift();
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ ๊ฑฐ
this.removeEventListeners(item);
// DOM์์ ์ ๊ฑฐ
item.remove();
}
console.log(`${removeCount}๊ฐ์ ์ค๋๋ ์์ดํ
์ ๊ฑฐ๋จ`);
}
}
removeEventListeners(element) {
// ํด๋ก ์ ๋ง๋ค์ด์ ๊ต์ฒดํ๋ฉด ๋ชจ๋ ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ์ ๊ฑฐ๋จ
const clone = element.cloneNode(true);
element.parentNode.replaceChild(clone, element);
}
createItemElement(data) {
const div = document.createElement('div');
div.className = 'scroll-item';
div.innerHTML = `
<h3>${data.title}</h3>
<p>${data.content}</p>
`;
return div;
}
// ํ์ฌ ์คํฌ๋กค ์์น ๊ธฐ์ค์ผ๋ก ๋ณด์ด์ง ์๋ ์์ ์ ๊ฑฐ
cleanupByViewport() {
const viewportTop = window.scrollY;
const viewportBottom = viewportTop + window.innerHeight;
const buffer = 1000; // ๋ฒํผ ์์ญ
this.items = this.items.filter(item => {
const rect = item.getBoundingClientRect();
const itemTop = rect.top + window.scrollY;
const itemBottom = itemTop + rect.height;
// ๋ทฐํฌํธ์์ ๋๋ฌด ๋ฉ๋ฆฌ ๋จ์ด์ง ์์ ์ ๊ฑฐ
if (itemBottom < viewportTop - buffer ||
itemTop > viewportBottom + buffer) {
item.remove();
return false;
}
return true;
});
}
}
// ์ฌ์ฉ
const manager = new InfiniteScrollManager(
document.querySelector('#content'),
100 // ์ต๋ 100๊ฐ ์์ดํ
๋ง ์ ์ง
);
๐จ UX ๊ฐ์ : ์ฌ์ฉ์๋ฅผ ๊ฐ๋์ํค๋ ๋ํ ์ผ
๊ธฐ์ ์ ์ผ๋ก ์๋ฒฝํ๊ฒ ๊ตฌํํ์ด๋ UX๊ฐ ๋์๋ฉด ์ฌ์ฉ์๋ค์ ๋ ๋๊ฐ์. ๋ฌดํ ์คํฌ๋กค์ UX๋ฅผ ๊ทน๋ํํ๋ ์ค์ ํ๋ค์ ์๋ ค๋๋ฆด๊ฒ์! ๐
1๏ธโฃ ๋ก๋ฉ ์ธ๋์ผ์ดํฐ: ๊ธฐ๋ค๋ฆผ์ ์ฆ๊ฒ๊ฒ
๋ก๋ฉ ์ค์ด๋ผ๋ ๊ฑธ ๋ช ํํ๊ฒ ์๋ ค์ฃผ๋ ๊ฒ ์ค์ํด์. ์ฌ์ฉ์๊ฐ "์ด? ๊ณ ์ฅ๋ฌ๋?" ํ๋ ์๊ฐ์ด ๋ค๋ฉด ์ ๋์ฃ !
// ์ค์ผ๋ ํค ์คํฌ๋ฆฐ ๊ตฌํ
class SkeletonLoader {
constructor(container) {
this.container = container;
}
show(count = 3) {
for (let i = 0; i < count; i++) {
const skeleton = this.createSkeleton();
this.container.appendChild(skeleton);
}
}
hide() {
const skeletons = this.container.querySelectorAll('.skeleton-item');
skeletons.forEach(skeleton => skeleton.remove());
}
createSkeleton() {
const div = document.createElement('div');
div.className = 'skeleton-item';
div.innerHTML = `
<div class="skeleton-header"></div>
<div class="skeleton-line"></div>
<div class="skeleton-line short"></div>
`;
return div;
}
}
// CSS (์คํ์ผ ์์)
const skeletonStyles = `
.skeleton-item {
padding: 20px;
margin: 10px 0;
background: white;
border-radius: 8px;
}
.skeleton-header,
.skeleton-line {
background: linear-gradient(
90deg,
#f0f0f0 25%,
#e0e0e0 50%,
#f0f0f0 75%
);
background-size: 200% 100%;
animation: loading 1.5s infinite;
border-radius: 4px;
}
.skeleton-header {
height: 24px;
width: 60%;
margin-bottom: 15px;
}
.skeleton-line {
height: 16px;
margin-bottom: 10px;
}
.skeleton-line.short {
width: 80%;
}
@keyframes loading {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
`;
// ์ฌ์ฉ
const loader = new SkeletonLoader(document.querySelector('#content'));
loader.show(5); // 5๊ฐ์ ์ค์ผ๋ ํค ํ์
// ๋ฐ์ดํฐ ๋ก๋ ํ
setTimeout(() => {
loader.hide();
// ์ค์ ์ฝํ
์ธ ์ถ๊ฐ
}, 2000);
โข ์คํผ๋: ๊ฐ๋จํ์ง๋ง ์ง๋ฃจํ๊ฒ ๋๊ปด์ง ์ ์์ด์
โข ํ๋ก๊ทธ๋ ์ค ๋ฐ: ์งํ ์ํฉ์ ์ ์ ์์ด์ ๊ธด ๋ก๋ฉ์ ์ ํฉํด์
2๏ธโฃ ์คํฌ๋กค ์์น ๋ณต์: ๋ค๋ก๊ฐ๊ธฐ ๋ฌธ์ ํด๊ฒฐ
์ฌ์ฉ์๊ฐ ์์ดํ ์ ํด๋ฆญํด์ ์์ธ ํ์ด์ง๋ก ๊ฐ๋ค๊ฐ ๋ค๋ก๊ฐ๊ธฐ๋ฅผ ๋๋ ์ ๋, ์ฒ์๋ถํฐ ๋ค์ ์คํฌ๋กคํด์ผ ํ๋ค๋ฉด? ์ต์ ์ UX์์! ๐ฑ
class ScrollPositionManager {
constructor(storageKey = 'scroll-position') {
this.storageKey = storageKey;
this.init();
}
init() {
// ํ์ด์ง ๋ก๋ ์ ์ ์ฅ๋ ์์น๋ก ๋ณต์
window.addEventListener('load', () => {
this.restore();
});
// ํ์ด์ง ๋ ๋๊ธฐ ์ ์์น ์ ์ฅ
window.addEventListener('beforeunload', () => {
this.save();
});
// ์ฃผ๊ธฐ์ ์ผ๋ก ์์น ์ ์ฅ (๋ค๋ก๊ฐ๊ธฐ ๋๋น)
let scrollTimer;
window.addEventListener('scroll', () => {
clearTimeout(scrollTimer);
scrollTimer = setTimeout(() => {
this.save();
}, 500);
});
}
save() {
const position = {
scrollY: window.scrollY,
timestamp: Date.now(),
page: this.getCurrentPage()
};
sessionStorage.setItem(
this.storageKey,
JSON.stringify(position)
);
}
restore() {
const saved = sessionStorage.getItem(this.storageKey);
if (!saved) return;
try {
const position = JSON.parse(saved);
// 5๋ถ ์ด๋ด์ ๋ฐ์ดํฐ๋ง ๋ณต์
if (Date.now() - position.timestamp < 5 * 60 * 1000) {
// ํ์ด์ง ๋ฐ์ดํฐ ๋จผ์ ๋ก๋
this.loadPagesUpTo(position.page).then(() => {
// ์คํฌ๋กค ์์น ๋ณต์
window.scrollTo({
top: position.scrollY,
behavior: 'instant'
});
});
}
} catch (error) {
console.error('์คํฌ๋กค ์์น ๋ณต์ ์คํจ:', error);
}
}
getCurrentPage() {
// ํ์ฌ ๋ก๋๋ ํ์ด์ง ๋ฒํธ ๋ฐํ
return parseInt(
document.querySelector('#content')
.getAttribute('data-current-page') || '1'
);
}
async loadPagesUpTo(targetPage) {
// ๋ชฉํ ํ์ด์ง๊น์ง ๋ฐ์ดํฐ ๋ก๋
const currentPage = this.getCurrentPage();
for (let page = 1; page <= targetPage; page++) {
if (page > currentPage) {
await loadMoreContent(page);
}
}
}
clear() {
sessionStorage.removeItem(this.storageKey);
}
}
// ์ฌ์ฉ
const scrollManager = new ScrollPositionManager();
// ์์ธ ํ์ด์ง๋ก ์ด๋ํ ๋
function navigateToDetail(itemId) {
scrollManager.save();
window.location.href = `/detail/${itemId}`;
}
3๏ธโฃ ์คํฌ๋กค ํฌ ํ ๋ฒํผ: ๋น ๋ฅธ ์ด๋ ์ ๊ณต
๋ฌดํ ์คํฌ๋กค์์ ๋งจ ์๋ก ๋์๊ฐ๊ธฐ๋ ํ์ ๊ธฐ๋ฅ์ด์์! ํนํ ๋ชจ๋ฐ์ผ์์๋ ๋์ฑ ์ค์ํ์ฃ . ๐ฑ
class ScrollToTopButton {
constructor() {
this.button = this.createButton();
this.init();
}
createButton() {
const button = document.createElement('button');
button.className = 'scroll-to-top';
button.innerHTML = 'โ';
button.setAttribute('aria-label', '๋งจ ์๋ก ์ด๋');
document.body.appendChild(button);
return button;
}
init() {
// ์คํฌ๋กค ์ด๋ฒคํธ๋ก ๋ฒํผ ํ์/์จ๊น
let scrollTimer;
window.addEventListener('scroll', () => {
clearTimeout(scrollTimer);
if (window.scrollY > 500) {
this.show();
} else {
this.hide();
}
// ์คํฌ๋กค ์ค์๋ ๋ฒํผ ์จ๊ธฐ๊ธฐ (์ ํ์ฌํญ)
this.button.style.opacity = '0.5';
scrollTimer = setTimeout(() => {
this.button.style.opacity = '1';
}, 150);
});
// ํด๋ฆญ ์ด๋ฒคํธ
this.button.addEventListener('click', () => {
this.scrollToTop();
});
}
show() {
this.button.classList.add('visible');
}
hide() {
this.button.classList.remove('visible');
}
scrollToTop() {
// ๋ถ๋๋ฌ์ด ์คํฌ๋กค
window.scrollTo({
top: 0,
behavior: 'smooth'
});
// ๋๋ ์ ๋๋ฉ์ด์
์ง์ ๊ตฌํ
// this.smoothScrollTo(0, 500);
}
smoothScrollTo(targetY, duration) {
const startY = window.scrollY;
const distance = targetY - startY;
const startTime = performance.now();
function animation(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
// easeInOutCubic ์ด์ง ํจ์
const ease = progress < 0.5
? 4 * progress * progress * progress
: 1 - Math.pow(-2 * progress + 2, 3) / 2;
window.scrollTo(0, startY + distance * ease);
if (progress < 1) {
requestAnimationFrame(animation);
}
}
requestAnimationFrame(animation);
}
}
// CSS ์คํ์ผ
const scrollToTopStyles = `
.scroll-to-top {
position: fixed;
bottom: 30px;
right: 30px;
width: 50px;
height: 50px;
background: #6c63ff;
color: white;
border: none;
border-radius: 50%;
font-size: 24px;
cursor: pointer;
opacity: 0;
visibility: hidden;
transform: translateY(20px);
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(108, 99, 255, 0.4);
z-index: 1000;
}
.scroll-to-top.visible {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.scroll-to-top:hover {
background: #5a52d5;
transform: translateY(-3px);
box-shadow: 0 6px 16px rgba(108, 99, 255, 0.5);
}
.scroll-to-top:active {
transform: translateY(-1px);
}
`;
// ์ฌ์ฉ
const scrollButton = new ScrollToTopButton();
4๏ธโฃ ์๋ฌ ์ฒ๋ฆฌ: ์คํจํด๋ ์ฐ์ํ๊ฒ
๋คํธ์ํฌ ์ค๋ฅ๋ ์ธ์ ๋ ๋ฐ์ํ ์ ์์ด์. ์ฌ์ฉ์์๊ฒ ๋ช ํํ ํผ๋๋ฐฑ๊ณผ ์ฌ์๋ ์ต์ ์ ์ ๊ณตํด์ผ ํด์! ๐
class ErrorHandler {
constructor(container) {
this.container = container;
this.retryCallback = null;
}
showError(message, retryCallback) {
this.retryCallback = retryCallback;
const errorElement = document.createElement('div');
errorElement.className = 'error-message';
errorElement.innerHTML = `
<div class="error-icon">โ ๏ธ</div>
<h3>์, ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ด์!</h3>
<p>${message}</p>
<button class="retry-button">๋ค์ ์๋</button>
`;
const retryButton = errorElement.querySelector('.retry-button');
retryButton.addEventListener('click', () => {
this.hideError();
if (this.retryCallback) {
this.retryCallback();
}
});
this.container.appendChild(errorElement);
}
hideError() {
const errorElement = this.container.querySelector('.error-message');
if (errorElement) {
errorElement.remove();
}
}
showNetworkError() {
this.showError(
'์ธํฐ๋ท ์ฐ๊ฒฐ์ ํ์ธํด์ฃผ์ธ์. ๋คํธ์ํฌ ์ํ๊ฐ ๋ถ์์ ํด์.',
this.retryCallback
);
}
showServerError() {
this.showError(
'์๋ฒ์ ์ผ์์ ์ธ ๋ฌธ์ ๊ฐ ์์ด์. ์ ์ ํ ๋ค์ ์๋ํด์ฃผ์ธ์.',
this.retryCallback
);
}
showEndOfContent() {
const endElement = document.createElement('div');
endElement.className = 'end-message';
endElement.innerHTML = `
<div class="end-icon">๐</div>
<h3>๋ชจ๋ ์ฝํ
์ธ ๋ฅผ ํ์ธํ์ด์!</h3>
<p>์๋ก์ด ์ฝํ
์ธ ๊ฐ ๊ณง ์
๋ฐ์ดํธ๋ ์์ ์ด์์.</p>
`;
this.container.appendChild(endElement);
}
}
// ๋ฌดํ ์คํฌ๋กค์ ์๋ฌ ์ฒ๋ฆฌ ํตํฉ
class RobustInfiniteScroll {
constructor(container, fetchFunction) {
this.container = container;
this.fetchFunction = fetchFunction;
this.errorHandler = new ErrorHandler(container);
this.currentPage = 1;
this.isLoading = false;
this.hasMore = true;
this.retryCount = 0;
this.maxRetries = 3;
}
async loadMore() {
if (this.isLoading || !this.hasMore) return;
this.isLoading = true;
this.errorHandler.hideError();
try {
const data = await this.fetchFunction(this.currentPage);
if (data.items.length === 0) {
this.hasMore = false;
this.errorHandler.showEndOfContent();
} else {
this.appendItems(data.items);
this.currentPage++;
this.retryCount = 0; // ์ฑ๊ณต ์ ์ฌ์๋ ์นด์ดํธ ๋ฆฌ์
}
} catch (error) {
console.error('๋ฐ์ดํฐ ๋ก๋ฉ ์คํจ:', error);
if (this.retryCount < this.maxRetries) {
this.retryCount++;
// ์ง์ ๋ฐฑ์คํ๋ก ์ฌ์๋
const delay = Math.pow(2, this.retryCount) * 1000;
setTimeout(() => {
this.loadMore();
}, delay);
this.errorHandler.showError(
`๋ก๋ฉ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ด์. ${this.retryCount}/${this.maxRetries} ์ฌ์๋ ์ค...`,
() => this.loadMore()
);
} else {
// ์ต๋ ์ฌ์๋ ํ์ ์ด๊ณผ
if (error.message.includes('network') || error.message.includes('fetch')) {
this.errorHandler.showNetworkError();
} else {
this.errorHandler.showServerError();
}
this.errorHandler.retryCallback = () => {
this.retryCount = 0;
this.loadMore();
};
}
} finally {
this.isLoading = false;
}
}
appendItems(items) {
items.forEach(item => {
const element = this.createItemElement(item);
this.container.appendChild(element);
});
}
createItemElement(data) {
const div = document.createElement('div');
div.className = 'content-item';
div.innerHTML = `
<h3>${data.title}</h3>
<p>${data.description}</p>
`;
return div;
}
}
// ์ฌ์ฉ
const infiniteScroll = new RobustInfiniteScroll(
document.querySelector('#content'),
async (page) => {
const response = await fetch(`/api/content?page=${page}`);
if (!response.ok) throw new Error('์๋ฒ ์ค๋ฅ');
return response.json();
}
);
โข ์ฌ์๋ ์ต์ ํญ์ ์ ๊ณต
โข ์ง์ ๋ฐฑ์คํ๋ก ์๋ฒ ๋ถํ ๋ฐฉ์ง
โข ๋คํธ์ํฌ/์๋ฒ ์ค๋ฅ ๊ตฌ๋ถ
โข ์ฌ์ฉ์ ์นํ์ ์ธ ์ธ์ด ์ฌ์ฉ
5๏ธโฃ ์ ๊ทผ์ฑ (Accessibility) ๊ณ ๋ คํ๊ธฐ
๋ฌดํ ์คํฌ๋กค์ ์คํฌ๋ฆฐ ๋ฆฌ๋ ์ฌ์ฉ์๋ ํค๋ณด๋ ์ฌ์ฉ์์๊ฒ ์ด๋ ค์ธ ์ ์์ด์. ๋ชจ๋ ์ฌ์ฉ์๋ฅผ ์ํ ๋ฐฐ๋ ค๊ฐ ํ์ํด์! โฟ
class AccessibleInfiniteScroll {
constructor(container) {
this.container = container;
this.liveRegion = this.createLiveRegion();
this.loadMoreButton = this.createLoadMoreButton();
}
createLiveRegion() {
// ์คํฌ๋ฆฐ ๋ฆฌ๋๋ฅผ ์ํ ๋ผ์ด๋ธ ๋ฆฌ์
const region = document.createElement('div');
region.setAttribute('role', 'status');
region.setAttribute('aria-live', 'polite');
region.setAttribute('aria-atomic', 'true');
region.className = 'sr-only'; // ์๊ฐ์ ์ผ๋ก ์จ๊น
document.body.appendChild(region);
return region;
}
createLoadMoreButton() {
// ์๋ ๋ก๋ฉ ๋์ ๋ฒํผ ์ ๊ณต (์ต์
)
const button = document.createElement('button');
button.className = 'load-more-button';
button.textContent = '๋ ๋ณด๊ธฐ';
button.setAttribute('aria-label', '๋ค์ ์ฝํ
์ธ ๋ถ๋ฌ์ค๊ธฐ');
button.addEventListener('click', () => {
this.loadMore();
});
this.container.appendChild(button);
return button;
}
announceLoading() {
this.liveRegion.textContent = '์๋ก์ด ์ฝํ
์ธ ๋ฅผ ๋ถ๋ฌ์ค๋ ์ค์
๋๋ค...';
}
announceLoaded(count) {
this.liveRegion.textContent =
`${count}๊ฐ์ ์๋ก์ด ํญ๋ชฉ์ด ์ถ๊ฐ๋์์ต๋๋ค.`;
}
announceError() {
this.liveRegion.textContent =
'์ฝํ
์ธ ๋ฅผ ๋ถ๋ฌ์ค๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์.';
}
announceEnd() {
this.liveRegion.textContent =
'๋ชจ๋ ์ฝํ
์ธ ๋ฅผ ํ์ธํ์ต๋๋ค.';
}
async loadMore() {
this.announceLoading();
this.loadMoreButton.disabled = true;
this.loadMoreButton.textContent = '๋ก๋ฉ ์ค...';
try {
const data = await fetchContent();
if (data.items.length > 0) {
this.appendItems(data.items);
this.announceLoaded(data.items.length);
// ์ฒซ ๋ฒ์งธ ์ ์์ดํ
์ ํฌ์ปค์ค (์ ํ์ฌํญ)
const firstNewItem = this.container.querySelector(
'.content-item:last-of-type'
);
if (firstNewItem) {
firstNewItem.setAttribute('tabindex', '-1');
firstNewItem.focus();
}
} else {
this.announceEnd();
this.loadMoreButton.style.display = 'none';
}
} catch (error) {
this.announceError();
} finally {
this.loadMoreButton.disabled = false;
this.loadMoreButton.textContent = '๋ ๋ณด๊ธฐ';
}
}
appendItems(items) {
items.forEach((item, index) => {
const element = document.createElement('article');
element.className = 'content-item';
element.setAttribute('role', 'article');
element.setAttribute('aria-label', `${item.title}`);
element.innerHTML = `
<h3 id="item-${item.id}">${item.title}</h3>
<p>${item.description}</p>
<a href="/detail/${item.id}"
aria-labelledby="item-${item.id}">
์์ธํ ๋ณด๊ธฐ
</a>
`;
this.container.insertBefore(element, this.loadMoreButton);
});
}
}
// ํค๋ณด๋ ๋ค๋น๊ฒ์ด์
๊ฐ์
class KeyboardNavigation {
constructor() {
this.currentIndex = -1;
this.items = [];
this.init();
}
init() {
document.addEventListener('keydown', (e) => {
this.items = Array.from(
document.querySelectorAll('.content-item')
);
switch(e.key) {
case 'j': // ๋ค์ ์์ดํ
case 'ArrowDown':
e.preventDefault();
this.navigateNext();
break;
case 'k': // ์ด์ ์์ดํ
case 'ArrowUp':
e.preventDefault();
this.navigatePrevious();
break;
}
});
}
navigateNext() {
if (this.currentIndex < this.items.length - 1) {
this.currentIndex++;
this.focusItem(this.currentIndex);
}
}
navigatePrevious() {
if (this.currentIndex > 0) {
this.currentIndex--;
this.focusItem(this.currentIndex);
}
}
focusItem(index) {
const item = this.items[index];
if (item) {
item.setAttribute('tabindex', '-1');
item.focus();
item.scrollIntoView({
behavior: 'smooth',
block: 'center'
});
}
}
}
// CSS for screen reader only
const srOnlyStyles = `
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
`;
// ์ฌ์ฉ
const accessibleScroll = new AccessibleInfiniteScroll(
document.querySelector('#content')
);
const keyboardNav = new KeyboardNavigation();
โ ํค๋ณด๋๋ก ๋ชจ๋ ๊ธฐ๋ฅ ์ ๊ทผ ๊ฐ๋ฅ
โ ์คํฌ๋ฆฐ ๋ฆฌ๋์ ์ํ ๋ณํ ์๋ฆผ
โ ํฌ์ปค์ค ๊ด๋ฆฌ (์ ์ฝํ ์ธ ๋ก๋ ์)
โ ์ถฉ๋ถํ ์์ ๋๋น
โ ๋ก๋ฉ/์๋ฌ ์ํ ๋ช ํํ ์ ๋ฌ
๐ฑ ๋ชจ๋ฐ์ผ ์ต์ ํ: ํฐ์น ํ๊ฒฝ์์์ ๋ฌดํ ์คํฌ๋กค
๋ชจ๋ฐ์ผ์์์ ๋ฌดํ ์คํฌ๋กค์ ๋ฐ์คํฌํฑ๊ณผ ๋ค๋ฅธ ์ ๊ทผ์ด ํ์ํด์. ํฐ์น ์ ์ค์ฒ, ์์ ํ๋ฉด, ๋๋ฆฐ ๋คํธ์ํฌ ๋ฑ์ ๊ณ ๋ คํด์ผ ํ์ฃ ! ๐ฒ
1๏ธโฃ ํ ํฌ ๋ฆฌํ๋ ์ (Pull to Refresh) ๊ตฌํ
๋ชจ๋ฐ์ผ ์ฑ์ฒ๋ผ ์๋๋ก ๋น๊ฒจ์ ์๋ก๊ณ ์นจํ๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ฉด UX๊ฐ ํจ์ฌ ์ข์์ ธ์!
class PullToRefresh {
constructor(container, onRefresh) {
this.container = container;
this.onRefresh = onRefresh;
this.startY = 0;
this.currentY = 0;
this.isDragging = false;
this.threshold = 80; // ์๋ก๊ณ ์นจ ํธ๋ฆฌ๊ฑฐ ๊ฑฐ๋ฆฌ
this.init();
}
init() {
// ์๋ก๊ณ ์นจ ์ธ๋์ผ์ดํฐ ์์ฑ
this.indicator = document.createElement('div');
this.indicator.className = 'pull-to-refresh-indicator';
this.indicator.innerHTML = `
<div class="refresh-icon">โ</div>
<div class="refresh-text">๋น๊ฒจ์ ์๋ก๊ณ ์นจ</div>
`;
this.container.insertBefore(
this.indicator,
this.container.firstChild
);
// ํฐ์น ์ด๋ฒคํธ ๋ฆฌ์ค๋
this.container.addEventListener('touchstart', (e) => {
if (window.scrollY === 0) {
this.startY = e.touches[0].pageY;
this.isDragging = true;
}
}, { passive: true });
this.container.addEventListener('touchmove', (e) => {
if (!this.isDragging) return;
this.currentY = e.touches[0].pageY;
const distance = this.currentY - this.startY;
if (distance > 0 && window.scrollY === 0) {
// ๋น๊ธฐ๋ ๊ฑฐ๋ฆฌ์ ๋ฐ๋ผ ์ธ๋์ผ์ดํฐ ์
๋ฐ์ดํธ
this.updateIndicator(distance);
}
}, { passive: true });
this.container.addEventListener('touchend', () => {
if (!this.isDragging) return;
const distance = this.currentY - this.startY;
if (distance > this.threshold) {
this.triggerRefresh();
} else {
this.resetIndicator();
}
this.isDragging = false;
});
}
updateIndicator(distance) {
const progress = Math.min(distance / this.threshold, 1);
const translateY = Math.min(distance * 0.5, this.threshold);
this.indicator.style.transform = `translateY(${translateY}px)`;
this.indicator.style.opacity = progress;
const icon = this.indicator.querySelector('.refresh-icon');
icon.style.transform = `rotate(${progress * 180}deg)`;
if (progress >= 1) {
this.indicator.querySelector('.refresh-text').textContent =
'๋์์ ์๋ก๊ณ ์นจ';
} else {
this.indicator.querySelector('.refresh-text').textContent =
'๋น๊ฒจ์ ์๋ก๊ณ ์นจ';
}
}
async triggerRefresh() {
this.indicator.classList.add('refreshing');
this.indicator.querySelector('.refresh-text').textContent =
'์๋ก๊ณ ์นจ ์ค...';
try {
await this.onRefresh();
// ์ฑ๊ณต ์ ๋๋ฉ์ด์
this.indicator.querySelector('.refresh-icon').textContent = 'โ';
await this.delay(500);
} catch (error) {
console.error('์๋ก๊ณ ์นจ ์คํจ:', error);
this.indicator.querySelector('.refresh-icon').textContent = 'โ';
await this.delay(500);
} finally {
this.resetIndicator();
}
}
resetIndicator() {
this.indicator.style.transform = 'translateY(0)';
this.indicator.style.opacity = '0';
this.indicator.classList.remove('refreshing');
setTimeout(() => {
this.indicator.querySelector('.refresh-icon').textContent = 'โ';
this.indicator.querySelector('.refresh-icon').style.transform =
'rotate(0deg)';
}, 300);
}
delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
// CSS ์คํ์ผ
const pullToRefreshStyles = `
.pull-to-refresh-indicator {
position: absolute;
top: -80px;
left: 0;
right: 0;
height: 80px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
opacity: 0;
transition: opacity 0.3s ease;
}
.pull-to-refresh-indicator.refreshing {
opacity: 1 !important;
}
.refresh-icon {
font-size: 24px;
margin-bottom: 8px;
transition: transform 0.3s ease;
}
.refresh-text {
font-size: 14px;
color: #666;
}
.pull-to-refresh-indicator.refreshing .refresh-icon {
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
`;
// ์ฌ์ฉ
const pullToRefresh = new PullToRefresh(
document.querySelector('#content'),
async () => {
// ์๋ก๊ณ ์นจ ๋ก์ง
await refreshContent();
}
);
2๏ธโฃ ํฐ์น ์ ์ค์ฒ ์ต์ ํ
๋ชจ๋ฐ์ผ์์๋ ํฐ์น ๋ฐ์์ฑ์ด ๋งค์ฐ ์ค์ํด์. ๋ถ๋๋ฌ์ด ์คํฌ๋กค๊ณผ ๋น ๋ฅธ ์๋ต์ด ํต์ฌ์ด์ฃ !
class TouchOptimizer {
constructor() {
this.init();
}
init() {
// ํฐ์น ์ง์ฐ ์ ๊ฑฐ
this.removeTouchDelay();
// ์คํฌ๋กค ์ฑ๋ฅ ๊ฐ์
this.optimizeScrolling();
// ํญ ํ์ด๋ผ์ดํธ ์ปค์คํฐ๋ง์ด์ง
this.customizeTapHighlight();
}
removeTouchDelay() {
// 300ms ํฐ์น ์ง์ฐ ์ ๊ฑฐ
document.addEventListener('touchstart', function() {}, {
passive: true
});
// CSS๋ก๋ ์ฒ๋ฆฌ
const style = document.createElement('style');
style.textContent = `
* {
touch-action: manipulation;
-webkit-tap-highlight-color: transparent;
}
a, button, .clickable {
cursor: pointer;
user-select: none;
-webkit-user-select: none;
}
`;
document.head.appendChild(style);
}
optimizeScrolling() {
// ์คํฌ๋กค ์ฑ๋ฅ์ ์ํ CSS ์ต์ ํ
const style = document.createElement('style');
style.textContent = `
.scroll-container {
-webkit-overflow-scrolling: touch;
overflow-y: scroll;
overscroll-behavior-y: contain;
}
.content-item {
will-change: transform;
contain: layout style paint;
}
/* ์คํฌ๋กค ์ค ์ ๋๋ฉ์ด์
์ผ์ ์ค์ง */
.scrolling * {
animation-play-state: paused !important;
transition: none !important;
}
`;
document.head.appendChild(style);
// ์คํฌ๋กค ์ค ํด๋์ค ์ถ๊ฐ/์ ๊ฑฐ
let scrollTimer;
window.addEventListener('scroll', () => {
document.body.classList.add('scrolling');
clearTimeout(scrollTimer);
scrollTimer = setTimeout(() => {
document.body.classList.remove('scrolling');
}, 150);
}, { passive: true });
}
customizeTapHighlight() {
// ์ปค์คํ
ํฐ์น ํผ๋๋ฐฑ
document.addEventListener('touchstart', (e) => {
const target = e.target.closest('a, button, .clickable');
if (target) {
target.classList.add('touch-active');
}
}, { passive: true });
document.addEventListener('touchend', (e) => {
const target = e.target.closest('a, button, .clickable');
if (target) {
setTimeout(() => {
target.classList.remove('touch-active');
}, 150);
}
}, { passive: true });
// CSS
const style = document.createElement('style');
style.textContent = `
.touch-active {
opacity: 0.7;
transform: scale(0.98);
transition: all 0.1s ease;
}
`;
document.head.appendChild(style);
}
}
// ์ฌ์ฉ
const touchOptimizer = new TouchOptimizer();
3๏ธโฃ ๋คํธ์ํฌ ์ํ ๊ฐ์ง ๋ฐ ๋์
๋ชจ๋ฐ์ผ์ ๋คํธ์ํฌ ์ํ๊ฐ ๋ถ์์ ํ ์ ์์ด์. ์ฐ๊ฒฐ ์ํ์ ๋ฐ๋ผ ๋์์ ์กฐ์ ํด์ผ ํด์! ๐ถ
class NetworkAwareLoader {
constructor() {
this.connection = navigator.connection ||
navigator.mozConnection ||
navigator.webkitConnection;
this.isOnline = navigator.onLine;
this.init();
}
init() {
// ์จ๋ผ์ธ/์คํ๋ผ์ธ ๊ฐ์ง
window.addEventListener('online', () => {
this.isOnline = true;
this.handleOnline();
});
window.addEventListener('offline', () => {
this.isOnline = false;
this.handleOffline();
});
// ๋คํธ์ํฌ ํ์
๋ณ๊ฒฝ ๊ฐ์ง
if (this.connection) {
this.connection.addEventListener('change', () => {
this.handleConnectionChange();
});
}
}
getConnectionType() {
if (!this.connection) return 'unknown';
return this.connection.effectiveType; // '4g', '3g', '2g', 'slow-2g'
}
shouldLoadImages() {
const type = this.getConnectionType();
// ๋๋ฆฐ ์ฐ๊ฒฐ์์๋ ์ด๋ฏธ์ง ๋ก๋ฉ ์ ํ
if (type === 'slow-2g' || type === '2g') {
return false;
}
// ๋ฐ์ดํฐ ์ ์ฝ ๋ชจ๋ ํ์ธ
if (this.connection && this.connection.saveData) {
return false;
}
return true;
}
getOptimalPageSize() {
const type = this.getConnectionType();
switch(type) {
case '4g':
return 20; // ํ ๋ฒ์ 20๊ฐ
case '3g':
return 10; // ํ ๋ฒ์ 10๊ฐ
case '2g':
case 'slow-2g':
return 5; // ํ ๋ฒ์ 5๊ฐ
default:
return 15;
}
}
handleOnline() {
console.log('์จ๋ผ์ธ ์ํ๋ก ์ ํ๋จ');
// ์คํ๋ผ์ธ ๋ฉ์์ง ์จ๊ธฐ๊ธฐ
this.hideOfflineMessage();
// ๋๊ธฐ ์ค์ธ ์์ฒญ ์ฌ์๋
this.retryPendingRequests();
}
handleOffline() {
console.log('์คํ๋ผ์ธ ์ํ๋ก ์ ํ๋จ');
// ์คํ๋ผ์ธ ๋ฉ์์ง ํ์
this.showOfflineMessage();
// ์งํ ์ค์ธ ์์ฒญ ์ทจ์
this.cancelPendingRequests();
}
handleConnectionChange() {
const type = this.getConnectionType();
console.log(`๋คํธ์ํฌ ํ์
๋ณ๊ฒฝ: ${type}`);
// ์ฐ๊ฒฐ ํ์
์ ๋ฐ๋ผ ๋ก๋ฉ ์ ๋ต ์กฐ์
if (type === 'slow-2g' || type === '2g') {
this.showSlowConnectionWarning();
}
}
showOfflineMessage() {
const message = document.createElement('div');
message.className = 'offline-message';
message.innerHTML = `
<div class="offline-icon">๐ก</div>
<p>์ธํฐ๋ท ์ฐ๊ฒฐ์ด ๋์ด์ก์ด์</p>
<small>์ฐ๊ฒฐ์ด ๋ณต๊ตฌ๋๋ฉด ์๋์ผ๋ก ๊ณ์๋ฉ๋๋ค</small>
`;
document.body.appendChild(message);
}
hideOfflineMessage() {
const message = document.querySelector('.offline-message');
if (message) {
message.remove();
}
}
showSlowConnectionWarning() {
const warning = document.createElement('div');
warning.className = 'slow-connection-warning';
warning.innerHTML = `
<p>โ ๏ธ ๋คํธ์ํฌ ์๋๊ฐ ๋๋ ค์. ๋ฐ์ดํฐ ์ ์ฝ ๋ชจ๋๋ก ์ ํํ ๊น์?</p>
<button onclick="this.parentElement.remove()">ํ์ธ</button>
`;
document.body.appendChild(warning);
setTimeout(() => {
warning.remove();
}, 5000);
}
async fetchWithNetworkAwareness(url, options = {}) {
if (!this.isOnline) {
throw new Error('์คํ๋ผ์ธ ์ํ์
๋๋ค');
}
// ๋๋ฆฐ ์ฐ๊ฒฐ์์๋ ํ์์์ ์ฆ๊ฐ
const type = this.getConnectionType();
const timeout = type === 'slow-2g' || type === '2g' ? 30000 : 10000;
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeout);
try {
const response = await fetch(url, {
...options,
signal: controller.signal
});
return response;
} finally {
clearTimeout(timeoutId);
}
}
retryPendingRequests() {
// ๊ตฌํ: ๋๊ธฐ ์ค์ธ ์์ฒญ ์ฌ์๋
}
cancelPendingRequests() {
// ๊ตฌํ: ์งํ ์ค์ธ ์์ฒญ ์ทจ์
}
}
// ์ฌ์ฉ
const networkLoader = new NetworkAwareLoader();
// ๋คํธ์ํฌ ์ํ์ ๋ฐ๋ฅธ ๋ก๋ฉ
async function loadContent(page) {
const pageSize = networkLoader.getOptimalPageSize();
const loadImages = networkLoader.shouldLoadImages();
const url = `/api/content?page=${page}&size=${pageSize}&images=${loadImages}`;
try {
const response = await networkLoader.fetchWithNetworkAwareness(url);
return await response.json();
} catch (error) {
console.error('๋ก๋ฉ ์คํจ:', error);
throw error;
}
}
โ ๋ถ๋๋ฌ์ด ์คํฌ๋กค (momentum scrolling)
โ ์ ์ ํ ํฐ์น ํ๊ฒ ํฌ๊ธฐ (์ต์ 44x44px)
โ ๋คํธ์ํฌ ์ํ ๊ฐ์ง ๋ฐ ๋์
โ ๋ฐ์ดํฐ ์ ์ฝ ๋ชจ๋ ์ง์
โ ์คํ๋ผ์ธ ์ํ ์ฒ๋ฆฌ
โ ๋ฐฐํฐ๋ฆฌ ํจ์จ ๊ณ ๋ ค
๐ญ ์ค์ ์์ : ์์ ํ ๋ฌดํ ์คํฌ๋กค ์์คํ
์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ชจ๋ ๋ด์ฉ์ ์ข ํฉํด์ ์ค์ ์์ ๋ฐ๋ก ์ฌ์ฉํ ์ ์๋ ์์ ํ ๋ฌดํ ์คํฌ๋กค ์์คํ ์ ๋ง๋ค์ด๋ณผ๊ฒ์! ์ด ์ฝ๋๋ ์ฌ๋ฅ๋ท ๊ฐ์ ์ค์ ์๋น์ค์์๋ ์ถฉ๋ถํ ์ฌ์ฉํ ์ ์๋ ์์ค์ด์์. ๐
/**
* ํ๋ก๋์
๋ ๋ฒจ ๋ฌดํ ์คํฌ๋กค ์์คํ
* ๋ชจ๋ ์ต์ ํ์ UX ๊ฐ์ ์ฌํญ์ด ํฌํจ๋ ์์ ํ ๊ตฌํ
*/
class ProductionInfiniteScroll {
constructor(options = {}) {
// ๊ธฐ๋ณธ ์ค์
this.container = options.container || document.querySelector('#content');
this.apiUrl = options.apiUrl || '/api/content';
this.pageSize = options.pageSize || 20;
this.threshold = options.threshold || 200;
this.maxItems = options.maxItems || 100;
// ์ํ ๊ด๋ฆฌ
this.state = {
currentPage: 1,
isLoading: false,
hasMore: true,
items: [],
error: null
};
// ์ปดํฌ๋ํธ ์ด๊ธฐํ
this.components = {
observer: null,
sentinel: null,
loader: null,
errorHandler: null,
scrollManager: null
};
// ์ด๋ฒคํธ ํธ๋ค๋ฌ ๋ฐ์ธ๋ฉ
this.handleIntersection = this.handleIntersection.bind(this);
this.loadMore = this.loadMore.bind(this);
this.init();
}
init() {
// ์ผํฐ๋ ์์ ์์ฑ
this.components.sentinel = this.createSentinel();
this.container.appendChild(this.components.sentinel);
// Intersection Observer ์ค์
this.components.observer = new IntersectionObserver(
this.handleIntersection,
{
rootMargin: `${this.threshold}px`,
threshold: 0
}
);
// ๊ด์ฐฐ ์์
this.components.observer.observe(this.components.sentinel);
// ๋ก๋ ์ปดํฌ๋ํธ
this.components.loader = new LoadingIndicator(this.container);
// ์๋ฌ ํธ๋ค๋ฌ
this.components.errorHandler = new ErrorHandler(this.container);
// ์คํฌ๋กค ์์น ๊ด๋ฆฌ์
this.components.scrollManager = new ScrollPositionManager();
// ์ด๊ธฐ ๋ฐ์ดํฐ ๋ก๋
this.loadMore();
}
createSentinel() {
const sentinel = document.createElement('div');
sentinel.id = 'scroll-sentinel';
sentinel.style.height = '1px';
return sentinel;
}
handleIntersection(entries) {
entries.forEach(entry => {
if (entry.isIntersecting &&
!this.state.isLoading &&
this.state.hasMore) {
this.loadMore();
}
});
}
async loadMore() {
if (this.state.isLoading || !this.state.hasMore) return;
this.state.isLoading = true;
this.state.error = null;
// ๋ก๋ฉ ์ธ๋์ผ์ดํฐ ํ์
this.components.loader.show();
try {
// ๋ฐ์ดํฐ ํ์นญ
const data = await this.fetchData(this.state.currentPage);
if (data.items.length === 0) {
// ๋ ์ด์ ๋ฐ์ดํฐ ์์
this.state.hasMore = false;
this.showEndMessage();
this.components.observer.unobserve(this.components.sentinel);
} else {
// ๋ฐ์ดํฐ ์ถ๊ฐ
await this.appendItems(data.items);
this.state.items.push(...data.items);
this.state.currentPage++;
// ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ
this.cleanupOldItems();
// ์ผํฐ๋ ์์น ์กฐ์
this.container.appendChild(this.components.sentinel);
}
} catch (error) {
console.error('๋ฐ์ดํฐ ๋ก๋ฉ ์คํจ:', error);
this.state.error = error;
this.components.errorHandler.show(error, () => this.loadMore());
} finally {
this.state.isLoading = false;
this.components.loader.hide();
}
}
async fetchData(page) {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000);
try {
const response = await fetch(
`${this.apiUrl}?page=${page}&size=${this.pageSize}`,
{
signal: controller.signal,
headers: {
'Content-Type': 'application/json'
}
}
);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
} finally {
clearTimeout(timeoutId);
}
}
async appendItems(items) {
const fragment = document.createDocumentFragment();
for (const item of items) {
const element = await this.createItemElement(item);
fragment.appendChild(element);
}
this.container.insertBefore(fragment, this.components.sentinel);
// ์ด๋ฏธ์ง ๋ ์ด์ง ๋ก๋ฉ ์ ์ฉ
this.applyLazyLoading();
}
async createItemElement(data) {
const article = document.createElement('article');
article.className = 'content-item';
article.setAttribute('data-id', data.id);
article.innerHTML = `
<div class="item-image">
<img data-src="${data.image}"
alt="${data.title}"
loading="lazy">
</div>
<div class="item-content">
<h3>${this.escapeHtml(data.title)}</h3>
<p>${this.escapeHtml(data.description)}</p>
<div class="item-meta">
<span class="date">${this.formatDate(data.createdAt)}</span>
<span class="author">${this.escapeHtml(data.author)}</span>
</div>
</div>
`;
// ํด๋ฆญ ์ด๋ฒคํธ
article.addEventListener('click', () => {
this.handleItemClick(data);
});
return article;
}
applyLazyLoading() {
const images = this.container.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.getAttribute('data-src');
img.removeAttribute('data-src');
imageObserver.unobserve(img);
}
});
});
images.forEach(img => imageObserver.observe(img));
}
cleanupOldItems() {
const items = this.container.querySelectorAll('.content-item');
if (items.length > this.maxItems) {
const removeCount = items.length - this.maxItems;
for (let i = 0; i < removeCount; i++) {
items[i].remove();
}
// ์ํ ์
๋ฐ์ดํธ
this.state.items = this.state.items.slice(removeCount);
console.log(`${removeCount}๊ฐ์ ์ค๋๋ ์์ดํ
์ ๊ฑฐ๋จ`);
}
}
handleItemClick(data) {
// ์คํฌ๋กค ์์น ์ ์ฅ
this.components.scrollManager.save();
// ์์ธ ํ์ด์ง๋ก ์ด๋
window.location.href = `/detail/${data.id}`;
}
showEndMessage() {
const message = document.createElement('div');
message.className = 'end-message';
message.innerHTML = `
<div class="end-icon">๐</div>
<h3>๋ชจ๋ ์ฝํ
์ธ ๋ฅผ ํ์ธํ์ด์!</h3>
<p>์๋ก์ด ์ฝํ
์ธ ๊ฐ ๊ณง ์
๋ฐ์ดํธ๋ ์์ ์ด์์.</p>
`;
this.container.appendChild(message);
}
// ์ ํธ๋ฆฌํฐ ๋ฉ์๋
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
formatDate(dateString) {
const date = new Date(dateString);
const now = new Date();
const diff = now - date;
const minutes = Math.floor(diff / 60000);
const hours = Math.floor(diff / 3600000);
const days = Math.floor(diff / 86400000);
if (minutes < 1) return '๋ฐฉ๊ธ ์ ';
if (minutes < 60) return `${minutes}๋ถ ์ `;
if (hours < 24) return `${hours}์๊ฐ ์ `;
if (days < 7) return `${days}์ผ ์ `;
return date.toLocaleDateString('ko-KR');
}
// ๊ณต๊ฐ API
refresh() {
// ์ ์ฒด ์๋ก๊ณ ์นจ
this.state.currentPage = 1;
this.state.hasMore = true;
this.state.items = [];
// ๊ธฐ์กด ์์ดํ
์ ๊ฑฐ
const items = this.container.querySelectorAll('.content-item');
items.forEach(item => item.remove());
// ์ฌ๋ก๋
this.loadMore();
}
destroy() {
// ๋ฆฌ์์ค ์ ๋ฆฌ
if (this.components.observer) {
this.components.observer.disconnect();
}
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ ๊ฑฐ
const items = this.container.querySelectorAll('.content-item');
items.forEach(item => item.remove());
// ์ผํฐ๋ ์ ๊ฑฐ
if (this.components.sentinel) {
this.components.sentinel.remove();
}
}
}
// ๋ก๋ฉ ์ธ๋์ผ์ดํฐ ์ปดํฌ๋ํธ
class LoadingIndicator {
constructor(container) {
this.container = container;
this.element = this.create();
}
create() {
const loader = document.createElement('div');
loader.className = 'loading-indicator';
loader.innerHTML = `
<div class="spinner"></div>
<p>๋ก๋ฉ ์ค...</p>
`;
return loader;
}
show() {
if (!this.element.parentElement) {
this.container.appendChild(this.element);
}
}
hide() {
if (this.element.parentElement) {
this.element.remove();
}
}
}
// ์ฌ์ฉ ์์
const infiniteScroll = new ProductionInfiniteScroll({
container: document.querySelector('#content'),
apiUrl: '/api/posts',
pageSize: 20,
threshold: 300,
maxItems: 100
});
// ์๋ก๊ณ ์นจ ๋ฒํผ
document.querySelector('#refresh-button')?.addEventListener('click', () => {
infiniteScroll.refresh();
});
// ํ์ด์ง ๋ ๋ ๋ ์ ๋ฆฌ
window.addEventListener('beforeunload', () => {
infiniteScroll.destroy();
});
โข ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ๋ก ๋ฌดํ ์ฆ๊ฐ ๋ฐฉ์ง
โข ์๋ฌ ์ฒ๋ฆฌ ๋ฐ ์ฌ์๋ ๋ก์ง
โข ์ด๋ฏธ์ง ๋ ์ด์ง ๋ก๋ฉ
โข ์คํฌ๋กค ์์น ๋ณต์
โข XSS ๋ฐฉ์ง (HTML ์ด์ค์ผ์ดํ)
โข ์ ๊ทผ์ฑ ๊ณ ๋ ค
โข ๋ชจ๋ํ๋ ๊ตฌ์กฐ๋ก ์ ์ง๋ณด์ ์ฉ์ด
๐ง ๋๋ฒ๊น ๋ฐ ํ ์คํธ: ์๋ฒฝํ ๋ฌดํ ์คํฌ๋กค์ ์ํ ์ฒดํฌ๋ฆฌ์คํธ
๋ฌดํ ์คํฌ๋กค์ ๊ตฌํํ๋ค๋ฉด ์ฒ ์ ํ ํ ์คํธ๊ฐ ํ์ํด์! ์ค์ ์ฌ์ฉ์๊ฐ ๊ฒช์ ์ ์๋ ๋ค์ํ ์ํฉ์ ์๋ฎฌ๋ ์ด์ ํด๋ด์ผ ํ์ฃ . ๐งช
1๏ธโฃ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
class PerformanceMonitor {
constructor() {
this.metrics = {
loadTimes: [],
renderTimes: [],
memoryUsage: [],
scrollEvents: 0
};
this.init();
}
init() {
// ๋ก๋ฉ ์๊ฐ ์ธก์
this.measureLoadTime();
// ๋ ๋๋ง ์๊ฐ ์ธก์
this.measureRenderTime();
// ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ๋ชจ๋ํฐ๋ง
this.monitorMemory();
// ์คํฌ๋กค ์ด๋ฒคํธ ๋น๋ ์ธก์
this.measureScrollFrequency();
}
measureLoadTime() {
const originalFetch = window.fetch;
window.fetch = async (...args) => {
const startTime = performance.now();
try {
const response = await originalFetch(...args);
const endTime = performance.now();
this.metrics.loadTimes.push(endTime - startTime);
this.logMetric('Load Time', endTime - startTime);
return response;
} catch (error) {
throw error;
}
};
}
measureRenderTime() {
const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (entry.entryType === 'measure') {
this.metrics.renderTimes.push(entry.duration);
this.logMetric('Render Time', entry.duration);
}
}
});
observer.observe({ entryTypes: ['measure'] });
}
monitorMemory() {
if (performance.memory) {
setInterval(() => {
const used = performance.memory.usedJSHeapSize;
const total = performance.memory.totalJSHeapSize;
const percentage = (used / total * 100).toFixed(2);
this.metrics.memoryUsage.push({
used,
total,
percentage,
timestamp: Date.now()
});
// ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ด 80% ์ด๊ณผ ์ ๊ฒฝ๊ณ
if (percentage > 80) {
console.warn(`โ ๏ธ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ๋์: ${percentage}%`);
}
}, 5000);
}
}
measureScrollFrequency() {
let scrollCount = 0;
let lastLog = Date.now();
window.addEventListener('scroll', () => {
scrollCount++;
this.metrics.scrollEvents++;
// 1์ด๋ง๋ค ๋ก๊ทธ
const now = Date.now();
if (now - lastLog > 1000) {
console.log(`์คํฌ๋กค ์ด๋ฒคํธ/์ด: ${scrollCount}`);
scrollCount = 0;
lastLog = now;
}
}, { passive: true });
}
logMetric(name, value) {
console.log(`๐ ${name}: ${value.toFixed(2)}ms`);
}
getReport() {
const avgLoadTime = this.average(this.metrics.loadTimes);
const avgRenderTime = this.average(this.metrics.renderTimes);
const currentMemory = this.metrics.memoryUsage[
this.metrics.memoryUsage.length - 1
];
return {
averageLoadTime: avgLoadTime,
averageRenderTime: avgRenderTime,
totalScrollEvents: this.metrics.scrollEvents,
currentMemoryUsage: currentMemory,
recommendations: this.getRecommendations(avgLoadTime, avgRenderTime)
};
}
average(arr) {
if (arr.length === 0) return 0;
return arr.reduce((a, b) => a + b, 0) / arr.length;
}
getRecommendations(loadTime, renderTime) {
const recommendations = [];
if (loadTime > 1000) {
recommendations.push('๋ก๋ฉ ์๊ฐ์ด ๋๋ฆฝ๋๋ค. ํ์ด์ง ํฌ๊ธฐ๋ฅผ ์ค์ด๊ฑฐ๋ ์บ์ฑ์ ๊ณ ๋ คํ์ธ์.');
}
if (renderTime > 100) {
recommendations.push('๋ ๋๋ง ์๊ฐ์ด ๋๋ฆฝ๋๋ค. ๊ฐ์ ์คํฌ๋กค๋ง์ ๊ณ ๋ คํ์ธ์.');
}
if (this.metrics.scrollEvents > 10000) {
recommendations.push('์คํฌ๋กค ์ด๋ฒคํธ๊ฐ ๋๋ฌด ๋ง์ต๋๋ค. ์ฐ๋กํ๋ง์ ์ ์ฉํ์ธ์.');
}
return recommendations;
}
}
// ์ฌ์ฉ
const monitor = new PerformanceMonitor();
// ๋ฆฌํฌํธ ํ์ธ
setTimeout(() => {
const report = monitor.getReport();
console.table(report);
}, 30000);
2๏ธโฃ ์๋ํ๋ ํ ์คํธ
// Jest๋ฅผ ์ฌ์ฉํ ๋ฌดํ ์คํฌ๋กค ํ
์คํธ
describe('InfiniteScroll', () => {
let container;
let infiniteScroll;
let mockFetch;
beforeEach(() => {
// DOM ์ค์
container = document.createElement('div');
container.id = 'content';
document.body.appendChild(container);
// Fetch ๋ชจํน
mockFetch = jest.fn();
global.fetch = mockFetch;
});
afterEach(() => {
document.body.removeChild(container);
jest.clearAllMocks();
});
test('์ด๊ธฐ ๋ฐ์ดํฐ๋ฅผ ๋ก๋ํด์ผ ํจ', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: async () => ({
items: [
{ id: 1, title: 'Item 1' },
{ id: 2, title: 'Item 2' }
]
})
});
infiniteScroll = new ProductionInfiniteScroll({
container,
apiUrl: '/api/test'
});
await new Promise(resolve => setTimeout(resolve, 100));
expect(mockFetch).toHaveBeenCalledTimes(1);
expect(container.querySelectorAll('.content-item')).toHaveLength(2);
});
test('์คํฌ๋กค ์ ์ถ๊ฐ ๋ฐ์ดํฐ๋ฅผ ๋ก๋ํด์ผ ํจ', async () => {
mockFetch
.mockResolvedValueOnce({
ok: true,
json: async () => ({ items: [{ id: 1, title: 'Item 1' }] })
})
.mockResolvedValueOnce({
ok: true,
json: async () => ({ items: [{ id: 2, title: 'Item 2' }] })
});
infiniteScroll = new ProductionInfiniteScroll({ container });
await new Promise(resolve => setTimeout(resolve, 100));
// Intersection Observer ํธ๋ฆฌ๊ฑฐ ์๋ฎฌ๋ ์ด์
const sentinel = container.querySelector('#scroll-sentinel');
const observer = infiniteScroll.components.observer;
// ์ผํฐ๋์ด ๋ทฐํฌํธ์ ๋ค์ด์ด
observer.callback([{
isIntersecting: true,
target: sentinel
}]);
await new Promise(resolve => setTimeout(resolve, 100));
expect(mockFetch).toHaveBeenCalledTimes(2);
expect(container.querySelectorAll('.content-item')).toHaveLength(2);
});
test('์๋ฌ ๋ฐ์ ์ ์๋ฌ ๋ฉ์์ง๋ฅผ ํ์ํด์ผ ํจ', async () => {
mockFetch.mockRejectedValueOnce(new Error('Network error'));
infiniteScroll = new ProductionInfiniteScroll({ container });
await new Promise(resolve => setTimeout(resolve, 100));
expect(container.querySelector('.error-message')).toBeTruthy();
});
test('๋ฐ์ดํฐ๊ฐ ์์ ๋ ์ข
๋ฃ ๋ฉ์์ง๋ฅผ ํ์ํด์ผ ํจ', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: async () => ({ items: [] })
});
infiniteScroll = new ProductionInfiniteScroll({ container });
await new Promise(resolve => setTimeout(resolve, 100));
expect(container.querySelector('.end-message')).toBeTruthy();
});
test('์ต๋ ์์ดํ
์๋ฅผ ์ด๊ณผํ๋ฉด ์ค๋๋ ์์ดํ
์ ์ ๊ฑฐํด์ผ ํจ', async () => {
const items = Array.from({ length: 150 }, (_, i) => ({
id: i + 1,
title: `Item ${i + 1}`
}));
mockFetch.mockResolvedValue({
ok: true,
json: async () => ({ items: items.slice(0, 20) })
});
infiniteScroll = new ProductionInfiniteScroll({
container,
maxItems: 100
});
// ์ฌ๋ฌ ๋ฒ ๋ก๋
for (let i = 0; i < 8; i++) {
await infiniteScroll.loadMore();
}
const itemCount = container.querySelectorAll('.content-item').length;
expect(itemCount).toBeLessThanOrEqual(100);
});
});
// Cypress๋ฅผ ์ฌ์ฉํ E2E ํ
์คํธ
describe('Infinite Scroll E2E', () => {
beforeEach(() => {
cy.visit('/infinite-scroll-demo');
});
it('ํ์ด์ง ๋ก๋ ์ ์ด๊ธฐ ์ฝํ
์ธ ๊ฐ ํ์๋์ด์ผ ํจ', () => {
cy.get('.content-item').should('have.length.at.least', 1);
});
it('์คํฌ๋กค ์ ์๋ก์ด ์ฝํ
์ธ ๊ฐ ๋ก๋๋์ด์ผ ํจ', () => {
cy.get('.content-item').its('length').then(initialCount => {
cy.scrollTo('bottom');
cy.wait(1000);
cy.get('.content-item').should('have.length.greaterThan', initialCount);
});
});
it('๋ก๋ฉ ์ธ๋์ผ์ดํฐ๊ฐ ํ์๋์ด์ผ ํจ', () => {
cy.scrollTo('bottom');
cy.get('.loading-indicator').should('be.visible');
cy.wait(1000);
cy.get('.loading-indicator').should('not.exist');
});
it('๋คํธ์ํฌ ์ค๋ฅ ์ ์๋ฌ ๋ฉ์์ง๊ฐ ํ์๋์ด์ผ ํจ', () => {
cy.intercept('GET', '/api/content*', {
statusCode: 500,
body: { error: 'Server error' }
});
cy.scrollTo('bottom');
cy.wait(1000);
cy.get('.error-message').should('be.visible');
cy.get('.retry-button').should('be.visible');
});
it('์ฌ์๋ ๋ฒํผ์ด ์๋ํด์ผ ํจ', () => {
cy.intercept('GET', '/api/content*', {
statusCode: 500
}).as('failedRequest');
cy.scrollTo('bottom');
cy.wait('@failedRequest');
cy.intercept('GET', '/api/content*', {
statusCode: 200,
body: { items: [{ id: 1, title: 'New Item' }] }
}).as('successRequest');
cy.get('.retry-button').click();
cy.wait('@successRequest');
cy.get('.error-message').should('not.exist');
});
it('๋ชจ๋ฐ์ผ ๋ทฐํฌํธ์์ ์ ์ ์๋ํด์ผ ํจ', () => {
cy.viewport('iphone-x');
cy.get('.content-item').should('be.visible');
cy.scrollTo('bottom');
cy.wait(1000);
cy.get('.loading-indicator').should('be.visible');
});
});
3๏ธโฃ ์ฒดํฌ๋ฆฌ์คํธ
| ํญ๋ชฉ | ํ์ธ ์ฌํญ | ์ค์๋ |
|---|---|---|
| ์ฑ๋ฅ | ์ด๊ธฐ ๋ก๋ฉ ์๊ฐ < 2์ด | โญโญโญ |
| ์ฑ๋ฅ | ์ถ๊ฐ ๋ก๋ฉ ์๊ฐ < 1์ด | โญโญโญ |
| ์ฑ๋ฅ | ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ์์ ์ | โญโญโญ |
| UX | ๋ก๋ฉ ์ธ๋์ผ์ดํฐ ํ์ | โญโญโญ |
| UX | ์๋ฌ ์ฒ๋ฆฌ ๋ฐ ์ฌ์๋ | โญโญโญ |
| UX | ์คํฌ๋กค ์์น ๋ณต์ | โญโญ |
| ์ ๊ทผ์ฑ | ํค๋ณด๋ ๋ค๋น๊ฒ์ด์ | โญโญ |
| ์ ๊ทผ์ฑ | ์คํฌ๋ฆฐ ๋ฆฌ๋ ์ง์ | โญโญ |
| ๋ชจ๋ฐ์ผ | ํฐ์น ์ต์ ํ | โญโญโญ |
| ๋ชจ๋ฐ์ผ | ๋คํธ์ํฌ ์ํ ๋์ | โญโญ |
| ๋ณด์ | XSS ๋ฐฉ์ง | โญโญโญ |
| ๋ณด์ | CSRF ํ ํฐ ์ฒ๋ฆฌ | โญโญ |
๐ก ์ค์ ํ: ์ฌ๋ฅ๋ท ๊ฐ๋ฐ์๋ค์ ๋ ธํ์ฐ
์ฌ๋ฅ๋ท์์ ํ๋ก๊ทธ๋๋ฐ ์ฌ๋ฅ์ ๊ณต์ ํ๋ ๊ฐ๋ฐ์๋ค์ด ์ค์ ๋ก ์ฌ์ฉํ๋ ๋ฌดํ ์คํฌ๋กค ํ๋ค์ ๋ชจ์๋ดค์ด์! ์ด๋ฐ ๋ํ ์ผ์ด ์ฌ์ฉ์ ๊ฒฝํ์ ํฌ๊ฒ ๋ฐ๊ฟ์. ๐ฏ
1๏ธโฃ ์ค์ผ๋ ํค ์คํฌ๋ฆฐ์ ์ ํํ ํ์ด๋ฐ
์ค์ผ๋ ํค ์คํฌ๋ฆฐ์ ๋๋ฌด ๋นจ๋ฆฌ ์ฌ๋ผ์ง๋ฉด ๊น๋นก์์ฒ๋ผ ๋ณด์ด๊ณ , ๋๋ฌด ๋ฆ๊ฒ ์ฌ๋ผ์ง๋ฉด ๋ต๋ตํด ๋ณด์ฌ์. ์ต์ ์ ํ์ด๋ฐ์ ์ต์ 300ms, ์ต๋ 1์ด์์. ์ค์ ๋ก๋ฉ์ด 200ms์ ๋๋๋ 300ms๋ ๋ณด์ฌ์ฃผ๋ ๊ฒ ์ข์์!
2๏ธโฃ ํ๋ฆฌํ์นญ์ ํฉ๊ธ ๋น์จ
๋ค์ ํ์ด์ง๋ฅผ ๋ฏธ๋ฆฌ ๋ถ๋ฌ์ค๋ ํ๋ฆฌํ์นญ์ ํ์ฌ ํ์ด์ง์ 70% ์ง์ ์์ ์์ํ๋ ๊ฒ ์ด์์ ์ด์์. ๋๋ฌด ์ผ์ฐ ํ๋ฉด ๋ถํ์ํ ์์ฒญ์ด ๋ง์์ง๊ณ , ๋๋ฌด ๋ฆ์ผ๋ฉด ์ฌ์ฉ์๊ฐ ๊ธฐ๋ค๋ ค์ผ ํด์.
3๏ธโฃ ์ด๋ฏธ์ง ์ต์ ํ ์ ๋ต
โข ์ธ๋ค์ผ์ WebP ํฌ๋งท์ผ๋ก ์ ๊ณต (50% ์ฉ๋ ๊ฐ์)
โข ๋ธ๋ฌ ํ๋ ์ด์คํ๋๋ 10x10px ์ดํ๋ก
โข ์ค์ํ ์ด๋ฏธ์ง๋ preload, ๋๋จธ์ง๋ lazy load
โข Intersection Observer์ rootMargin์ 50px~100px์ด ์ ๋นํด์
4๏ธโฃ ์๋ฌ ๋ฉ์์ง๋ ์น๊ทผํ๊ฒ
"Error 500: Internal Server Error" ๋์
"์, ์ ์ ๋ฌธ์ ๊ฐ ์๊ฒผ์ด์! ๋ค์ ์๋ํด๋ณผ๊น์? ๐"
๊ธฐ์ ์ ์ธ ์ฉ์ด๋ณด๋ค๋ ์ฌ์ฉ์๊ฐ ์ดํดํ๊ธฐ ์ฌ์ด ์ธ์ด๋ฅผ ์ฌ์ฉํ์ธ์. ์ด๋ชจ์ง๋ฅผ ์ ์ ํ ํ์ฉํ๋ฉด ๋ ์น๊ทผํด์ ธ์!
5๏ธโฃ ๋ก๋ฉ ์ ๋๋ฉ์ด์ ์ ์ฌ๋ฆฌํ
๋จ์ํ ์คํผ๋๋ณด๋ค๋ ์งํ ์ํฉ์ ๋ณด์ฌ์ฃผ๋ ์ ๋๋ฉ์ด์ ์ด ์ฒด๊ฐ ์๋๋ฅผ ๋น ๋ฅด๊ฒ ๋ง๋ค์ด์. "์ฝํ ์ธ ๋ฅผ ๋ถ๋ฌ์ค๋ ์ค... 80%" ๊ฐ์ ํผ๋๋ฐฑ์ด ์์ผ๋ฉด ์ฌ์ฉ์๊ฐ ๋ ๋ต๋ตํดํด์!
6๏ธโฃ ๋ฌดํ ์คํฌ๋กค vs ํ์ด์ง๋ค์ด์ ์ ํ ๊ธฐ์ค
๋ฌดํ ์คํฌ๋กค์ด ์ข์ ๊ฒฝ์ฐ:
โข ์์
๋ฏธ๋์ด ํผ๋
โข ์ด๋ฏธ์ง ๊ฐค๋ฌ๋ฆฌ
โข ์ค์๊ฐ ์
๋ฐ์ดํธ ์ฝํ
์ธ
โข ํ์ ์ค์ฌ์ ๊ฒฝํ
ํ์ด์ง๋ค์ด์
์ด ์ข์ ๊ฒฝ์ฐ:
โข ๊ฒ์ ๊ฒฐ๊ณผ
โข ์ ์์๊ฑฐ๋ ์ํ ๋ชฉ๋ก
โข ํน์ ์์ดํ
์ ์ฐพ์์ผ ํ๋ ๊ฒฝ์ฐ
โข SEO๊ฐ ์ค์ํ ๊ฒฝ์ฐ
7๏ธโฃ ๋๋ฐ์ด์ฑ vs ์ฐ๋กํ๋ง
๋๋ฐ์ด์ฑ: ๋ง์ง๋ง ์ด๋ฒคํธ ํ ์ผ์ ์๊ฐ ๋๊ธฐ
โ ๊ฒ์ ์
๋ ฅ, ์๋์ฐ ๋ฆฌ์ฌ์ด์ฆ์ ์ ํฉ
์ฐ๋กํ๋ง: ์ผ์ ์๊ฐ๋ง๋ค ํ ๋ฒ๋ง ์คํ
โ ์คํฌ๋กค ์ด๋ฒคํธ์ ์ ํฉ
๋ฌดํ ์คํฌ๋กค์๋ ์ฐ๋กํ๋ง์ ์ฌ์ฉํ์ธ์! 200ms~300ms ๊ฐ๊ฒฉ์ด ์ ๋นํด์.
8๏ธโฃ ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐฉ์ง
โข ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ ๋ฐ๋์ ์ ๊ฑฐํ์ธ์
โข DOM ์์ ์ฐธ์กฐ๋ฅผ null๋ก ์ค์ ํ์ธ์
โข ํ์ด๋จธ๋ clearTimeout/clearInterval๋ก ์ ๋ฆฌํ์ธ์
โข Observer๋ disconnect()๋ก ํด์ ํ์ธ์
โข ํฐ ๋ฐฐ์ด์ ์ฃผ๊ธฐ์ ์ผ๋ก ๋น์ฐ์ธ์
9๏ธโฃ A/B ํ ์คํธ ์์ด๋์ด
โข ํ์ด์ง ํฌ๊ธฐ: 10๊ฐ vs 20๊ฐ vs 30๊ฐ
โข ๋ก๋ฉ ํธ๋ฆฌ๊ฑฐ ์ง์ : 100px vs 200px vs 300px
โข ๋ก๋ฉ ์ธ๋์ผ์ดํฐ: ์คํผ๋ vs ์ค์ผ๋ ํค vs ํ๋ก๊ทธ๋ ์ค ๋ฐ
โข ์๋ ๋ก๋ฉ vs ๋ฒํผ ํด๋ฆญ
๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ต์ ์ ์ค์ ์ ์ฐพ์ผ์ธ์!
๐ ์ฑ๋ฅ ์ต์ ํ ์ฒดํฌ๋ฆฌ์คํธ
โ
์ด๋ฏธ์ง ๋ ์ด์ง ๋ก๋ฉ ์ ์ฉ
โ
๊ฐ์ ์คํฌ๋กค๋ง ๊ณ ๋ ค (1000๊ฐ ์ด์)
โ
์ฐ๋กํ๋ง ์ ์ฉ (200ms)
โ
๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ (์ต๋ 100๊ฐ ์ ์ง)
โ
์บ์ฑ ์ ๋ต ์๋ฆฝ
โ
CDN ํ์ฉ
โ
์์ถ (gzip/brotli)
โ
HTTP/2 ์ฌ์ฉ
โ
ํ๋ฆฌํ์นญ ์ ์ฉ
โ
์๋น์ค ์์ปค ํ์ฉ
๐ ๋ง๋ฌด๋ฆฌ: ๋ฌดํ ์คํฌ๋กค ๋ง์คํฐ๊ฐ ๋๋ ๊ธธ
์, ์ฌ๊ธฐ๊น์ง ๋ฌดํ ์คํฌ๋กค์ ๋ชจ๋ ๊ฒ์ ์์๋ดค์ด์! ์ฒ์์๋ ๋ณต์กํด ๋ณด์์ง๋ง, ํ๋์ฉ ๋ฏ์ด๋ณด๋ ๊ทธ๋ ๊ฒ ์ด๋ ต์ง ์์ฃ ? ๐
๋ฌดํ ์คํฌ๋กค์ ๋จ์ํ "์คํฌ๋กคํ๋ฉด ์ฝํ
์ธ ๊ฐ ๋์จ๋ค"๋ ๊ธฐ๋ฅ์ ๋์ด์, ์ฌ์ฉ์ ๊ฒฝํ์ ๊ทน๋ํํ๋ ์์ ์ด์์. ์ฑ๋ฅ, UX, ์ ๊ทผ์ฑ, ๋ชจ๋ฐ์ผ ์ต์ ํ ๋ฑ ๋ชจ๋ ์์๊ฐ ์กฐํ๋กญ๊ฒ ์ด์ฐ๋ฌ์ ธ์ผ ์ง์ ํ ๋ฌดํ ์คํฌ๋กค์ด ์์ฑ๋์ฃ .
ํต์ฌ ํฌ์ธํธ ์ ๋ฆฌ:
๐ฏ ๊ตฌํ ๋ฐฉ๋ฒ
โข Intersection Observer๊ฐ ๊ฐ์ฅ ํ๋์ ์ด๊ณ ํจ์จ์ ์ด์์
โข ์คํฌ๋กค ์ด๋ฒคํธ๋ ์ฐ๋กํ๋ง๊ณผ ํจ๊ป ์ฌ์ฉํ์ธ์
โข ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋น ๋ฅธ ๊ตฌํ์ ์ข์ง๋ง ์ปค์คํฐ๋ง์ด์ง์ด ์ ํ์ ์ด์์
โก ์ฑ๋ฅ ์ต์ ํ
โข ๊ฐ์ ์คํฌ๋กค๋ง์ผ๋ก DOM ์์ ์๋ฅผ ์ ํํ์ธ์
โข ์ด๋ฏธ์ง ๋ ์ด์ง ๋ก๋ฉ์ ํ์์์
โข ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ๋ฅผ ํตํด ์ค๋๋ ์์ดํ
์ ์ ๋ฆฌํ์ธ์
โข ์บ์ฑ๊ณผ ํ๋ฆฌํ์นญ์ผ๋ก ์ฒด๊ฐ ์๋๋ฅผ ๋์ด์ธ์
๐จ UX ๊ฐ์
โข ๋ก๋ฉ ์ํ๋ฅผ ๋ช
ํํ๊ฒ ํ์ํ์ธ์ (์ค์ผ๋ ํค ์คํฌ๋ฆฐ ์ถ์ฒ)
โข ์๋ฌ ์ฒ๋ฆฌ์ ์ฌ์๋ ์ต์
์ ์ ๊ณตํ์ธ์
โข ์คํฌ๋กค ์์น ๋ณต์์ผ๋ก ๋ค๋ก๊ฐ๊ธฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ธ์
โข ์ ๊ทผ์ฑ์ ๊ณ ๋ คํด์ ๋ชจ๋ ์ฌ์ฉ์๋ฅผ ๋ฐฐ๋ คํ์ธ์
๐ฑ ๋ชจ๋ฐ์ผ ์ต์ ํ
โข ํฐ์น ์ ์ค์ฒ๋ฅผ ์ต์ ํํ์ธ์
โข ๋คํธ์ํฌ ์ํ์ ๋ฐ๋ผ ๋์์ ์กฐ์ ํ์ธ์
โข Pull to Refresh ๊ฐ์ ๋ชจ๋ฐ์ผ ์นํ์ ๊ธฐ๋ฅ์ ์ถ๊ฐํ์ธ์
์ฌ๋ฅ๋ท์์ ํ๋ก๊ทธ๋๋ฐ ์ฌ๋ฅ์ ๊ณต์ ํ๋ ๋ง์ ๊ฐ๋ฐ์๋ค์ด ์ด๋ฐ ๊ธฐ๋ฒ๋ค์ ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํ๊ณ ์์ด์. ์ฌ๋ฌ๋ถ๋ ์ด ๊ฐ์ด๋๋ฅผ ์ฐธ๊ณ ํด์ ๋ฉ์ง ๋ฌดํ ์คํฌ๋กค์ ๊ตฌํํด๋ณด์ธ์! ๐ช
์ฒ์์๋ ๊ธฐ๋ณธ์ ์ธ ๊ตฌํ๋ถํฐ ์์ํ๊ณ , ์ ์ง์ ์ผ๋ก ์ต์ ํ์ UX ๊ฐ์ ์ ์ถ๊ฐํด๋๊ฐ๋ ๊ฒ ์ข์์. ์๋ฒฝํ ๋ฌดํ ์คํฌ๋กค์ ํ๋ฃจ์์นจ์ ๋ง๋ค์ด์ง์ง ์์์. ์ฌ์ฉ์ ํผ๋๋ฐฑ์ ๋ฃ๊ณ , ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ๊ณ , ๊ณ์ ๊ฐ์ ํด๋๊ฐ๋ ๊ณผ์ ์ด ์ค์ํ์ฃ .
๋ค์ ๋จ๊ณ:
1. ๊ฐ๋จํ ํ๋กํ ํ์
๋ง๋ค๊ธฐ
2. Intersection Observer๋ก ์
๊ทธ๋ ์ด๋
3. ๋ก๋ฉ ์ธ๋์ผ์ดํฐ ์ถ๊ฐ
4. ์๋ฌ ์ฒ๋ฆฌ ๊ตฌํ
5. ์ฑ๋ฅ ์ต์ ํ ์ ์ฉ
6. ๋ชจ๋ฐ์ผ ์ต์ ํ
7. ์ ๊ทผ์ฑ ๊ฐ์
8. A/B ํ
์คํธ๋ก ์ต์ ๊ฐ ์ฐพ๊ธฐ
์ด ๊ฐ์ด๋๊ฐ ์ฌ๋ฌ๋ถ์ ํ๋ก์ ํธ์ ๋์์ด ๋๊ธธ ๋ฐ๋ผ์! ๋ฌดํ ์คํฌ๋กค ๊ตฌํ ์ค์ ๋งํ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด, ์ฌ๋ฅ๋ท์ ๊ฐ๋ฐ์ ์ปค๋ฎค๋ํฐ์์ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค๊ณผ ์ํตํด๋ณด๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์์. ํจ๊ป ์ฑ์ฅํ๋ ๊ฒ ๊ฐ๋ฐ์์ ๋งค๋ ฅ์ด๋๊น์! ๐
ํ๋ณตํ ์ฝ๋ฉ ๋์ธ์! ์ฌ๋ฌ๋ถ์ ๋ฌดํ ์คํฌ๋กค์ด ์ฌ์ฉ์๋ค์๊ฒ ์ต๊ณ ์ ๊ฒฝํ์ ์ ์ฌํ๊ธธ ์์ํ ๊ฒ์! ๐โจ
๐ ๋ ๋ง์ ๊ฐ๋ฐ ์ง์์ด ํ์ํ์ ๊ฐ์?
์ฌ๋ฅ๋ท์์๋ ๋ค์ํ ํ๋ก๊ทธ๋๋ฐ ์ฌ๋ฅ์ ๊ฐ์ง ๊ฐ๋ฐ์๋ค์ด
์ค์ ๊ฒฝํ๊ณผ ๋
ธํ์ฐ๋ฅผ ๊ณต์ ํ๊ณ ์์ด์!
JavaScript, React, Vue, ์ฑ๋ฅ ์ต์ ํ ๋ฑ
๊ถ๊ธํ ์ฃผ์ ๊ฐ ์๋ค๋ฉด ์ฌ๋ฅ๋ท์ ๋ฐฉ๋ฌธํด๋ณด์ธ์! ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.