디버깅과 성능 최적화
AI와 함께 더 빠르게 디버깅하고 성능을 최적화해요 — 에러 메시지 해석, 레이아웃 이슈 수정, Core Web Vitals 개선, 사이트 속도 감사.
프리미엄 강좌 콘텐츠
이 레슨은 프리미엄 강좌의 일부예요. Pro로 업그레이드하면 모든 프리미엄 강좌와 콘텐츠를 이용할 수 있어요.
- 모든 프리미엄 강좌 이용
- 1000개 이상의 AI 스킬 템플릿 포함
- 매주 새로운 콘텐츠 추가
🔄 복습: 지난 레슨에서 인터랙티브 기능을 만들고 API에 연결했어요 — 데이터 페칭, 검색 필터, 접근 가능한 컴포넌트. 이제 모든 것이 안정적으로 작동하고 빠르게 로드되게 만들어볼게요.
AI로 디버깅하기
디버깅 프롬프트 패턴
에러가 발생했을 때, AI에게 전체 그림을 제공하세요:
I'm getting an error in my JavaScript:
Error message: [exact error from console]
Error location: [file name, line number if available]
The code:
[paste the relevant function or section — not the entire file]
What I expected: [what should happen]
What actually happens: [what's happening instead]
What I've tried: [any fixes you've already attempted]
Browser: [Chrome/Firefox/Safari/Edge]
Recent changes: [what did you change before the error appeared?]
Diagnose the issue and provide a fix.
✅ 확인 질문: 디버깅 프롬프트에 “이미 시도한 것"을 포함하는 이유는?
AI가 이미 시도해서 실패한 해결책을 제안하는 것을 방지해요. API URL이 정확한지 이미 확인했다면, AI는 그것을 건너뛰고 더 깊이 볼 수 있어요 — CORS 문제인지, 응답 형식이 변경됐는지, 캐싱 이슈인지. 또한 여러분의 디버깅이 어디서 잘못됐는지 AI에게 보여주면, 그것이 종종 실제 문제를 드러내요.
CSS 레이아웃 디버깅
My CSS layout isn't working as expected:
Expected: [describe or sketch the layout you want]
Actual: [describe what's happening instead]
HTML structure:
[paste the relevant HTML]
CSS:
[paste the relevant CSS]
Viewport width where it breaks: [specific breakpoint or range]
Browser: [which browser]
Common issues to check:
- Flexbox alignment and wrapping behavior
- Grid track sizing and overflow
- Box model (is padding/border causing unexpected width?)
- Position context (is the parent positioned?)
- Z-index stacking context issues
크로스 브라우저 이슈
This code works in [browser A] but breaks in [browser B]:
The code:
[paste relevant HTML/CSS/JS]
Works correctly in: [browser + version]
Breaks in: [browser + version]
What breaks: [describe the specific behavior difference]
Check for:
1. CSS properties that need vendor prefixes
2. JavaScript APIs not supported in the target browser
3. CSS layout differences between rendering engines
4. Default browser styles that differ
한국 사용자의 브라우저 사용 패턴을 고려하면, Chrome이 압도적이지만 삼성 인터넷 브라우저도 상당한 점유율을 가져요. 특히 모바일에서요. 크로스 브라우저 테스팅에서 이 부분도 잊지 마세요.
성능 최적화
이미지 최적화
이미지는 보통 페이지에서 가장 큰 에셋이에요:
Optimize the images on my website for performance:
Current setup:
- [number] images on the page
- Largest image: [size in KB/MB]
- Image formats: [jpg/png/svg]
Generate:
1. Responsive image HTML using srcset and sizes attributes
2. Lazy loading implementation (loading="lazy" for below-fold images)
3. Appropriate image format recommendations (WebP with fallbacks)
4. Width and height attributes to prevent layout shift (CLS)
5. Art direction with picture element for different screen sizes
Example image to optimize: [describe one of your images]
JavaScript 성능
Review this JavaScript for performance issues:
[paste your JavaScript]
Check for:
1. DOM queries inside loops (should cache references)
2. Missing debounce/throttle on scroll or resize handlers
3. Large arrays processed synchronously (should they be chunked?)
4. Event listeners not cleaned up (memory leaks)
5. Synchronous operations that could be async
6. Unnecessary re-renders or DOM updates
For each issue, show the current code and the optimized version.
Core Web Vitals 감사
Audit my website HTML/CSS/JS for Core Web Vitals performance:
[paste your HTML, or describe the page structure]
Check and optimize:
LCP (Largest Contentful Paint — target: < 2.5s):
- Is the hero image or largest element preloaded?
- Are render-blocking resources minimized?
- Is critical CSS inlined or prioritized?
CLS (Cumulative Layout Shift — target: < 0.1):
- Do all images have width and height attributes?
- Are fonts loaded with font-display: swap?
- Do dynamic elements (ads, embeds) have reserved space?
INP (Interaction to Next Paint — target: < 200ms):
- Are event handlers efficient?
- Is heavy JavaScript deferred?
- Are long tasks broken into smaller chunks?
Provide specific code fixes for each issue found.
✅ 확인 질문: 이미지에 명시적 width와 height 속성이 있어야 하는 이유는?
치수가 없으면 브라우저는 이미지가 로드될 때까지 얼마나 많은 공간이 필요한지 몰라요. 이미지 아래 콘텐츠가 위에 있다가, 이미지가 나타나면 아래로 밀려나요 — 이것이 레이아웃 시프트(CLS)예요. width와 height를 설정하면 브라우저가 이미지 로드 전에 올바른 공간을 예약해요. 콘텐츠는 그대로 있고, 이미지가 예약된 공간을 채우고, 아무것도 뛰지 않아요.
접근성 감사
Audit this page for accessibility issues:
[paste your HTML]
Check against WCAG 2.1 AA:
1. Color contrast (text against backgrounds — need 4.5:1 ratio)
2. Keyboard navigation (can every interactive element be reached and used?)
3. Screen reader compatibility (landmarks, labels, live regions)
4. Focus management (visible focus indicators, logical tab order)
5. Alternative text (meaningful for informative images, empty for decorative)
6. Form accessibility (labels, error messages, required indicators)
7. Motion sensitivity (respects prefers-reduced-motion)
Prioritize issues by severity: Critical → Major → Minor.
한국의 KWCAG 2.2 가이드라인도 WCAG 2.1과 큰 틀에서 동일해요. 한국 공공기관이나 대기업 사이트는 웹 접근성 인증이 필수이므로, 이 기준을 미리 익혀두면 실무에서도 큰 도움이 돼요.
연습: 프로젝트 디버깅과 최적화
- Chrome DevTools에서 프로젝트를 열고 콘솔 에러를 확인하세요
- Lighthouse(Chrome DevTools → Lighthouse 탭)를 실행하고 점수를 기록하세요
- Core Web Vitals 감사 프롬프트를 페이지에 사용하세요
- 폴드 아래 모든 이미지에 레이지 로딩을 추가하세요
- Lighthouse가 식별한 상위 3개 이슈를 수정하세요
- Lighthouse를 다시 실행하고 점수를 비교하세요
핵심 정리
- 효과적인 디버깅 프롬프트에는 에러, 코드, 기대한 것, 실제 동작, 이미 시도한 것을 포함하세요
- Core Web Vitals(LCP, CLS, INP)는 검색 순위와 사용자 경험 모두에 영향을 줘요 — 목표: LCP < 2.5초, CLS < 0.1, INP < 200ms
- 폴드 아래 이미지를 레이지 로딩하면 이미지가 많은 페이지에서 초기 로드 시간을 50~70% 줄여요
- 이미지에 항상 명시적 width와 height를 설정해서 레이아웃 시프트(CLS)를 방지하세요
- 루프 밖에서 DOM 참조를 캐시하고, 스크롤/리사이즈 핸들러에 디바운스를 적용하고, 이벤트 리스너를 정리해서 메모리 누수를 방지하세요
- 최적화 전후로 Lighthouse를 실행해서 실제 개선을 측정하세요
다음 레슨: 웹사이트를 배포해요 — 호스팅, 도메인 설정, SEO 최적화, 그리고 사이트를 라이브로 올리기.
이해도 체크
먼저 위의 퀴즈를 완료하세요
레슨 완료!