Performance Wiki

커뮤니티 위키 & 포럼

카테고리

프론트엔드 개발

최근 수정

2024년 1월

기여자

활성 기여자 42명

관련 주제

HTMLJavaScriptWeb Design

Optimize your web apps for speed and efficiency

Code Splitting

Split your bundle into smaller chunks to reduce initial load time and improve performance.

// Dynamic import with React.lazy
const HeavyComponent = React.lazy(() => import('./HeavyComponent'));

function App() {
  return (
    <Suspense fallback={<Loading />}>
      <HeavyComponent />
    </Suspense>
  );
}

// Route-based code splitting
const routes = [
  {
    path: '/dashboard',
    component: React.lazy(() => import('./Dashboard')),
  },
  {
    path: '/profile',
    component: React.lazy(() => import('./Profile')),
  },
];

Image Optimization

Optimize images for better performance using modern formats, lazy loading, and responsive images.

<!-- Responsive images with srcset -->
<img
  src="small.jpg"
  srcset="small.jpg 400w, medium.jpg 800w, large.jpg 1200w"
  sizes="(max-width: 400px) 400px, (max-width: 800px) 800px, 1200px"
  alt="Responsive image"
  loading="lazy"
/>

<!-- Next.js Image component -->
<Image
  src="/photo.jpg"
  alt="Optimized image"
  width={800}
  height={600}
  loading="lazy"
  placeholder="blur"
/>

Memoization

Use React.memo, useMemo, and useCallback to prevent unnecessary re-renders and expensive calculations.

// Memoize component
const ExpensiveComponent = React.memo(({ data }) => {
  return <div>{/* render */}</div>;
});

// Memoize expensive calculation
function Component({ items }) {
  const total = useMemo(() => {
    return items.reduce((sum, item) => sum + item.price, 0);
  }, [items]);

  return <div>Total: {total}</div>;
}

// Memoize callback
function Parent() {
  const handleClick = useCallback(() => {
    console.log('clicked');
  }, []);

  return <Child onClick={handleClick} />;
}

토론 (0)

내 아바타

의견을 남겨 주세요

아직 댓글이 없습니다. 첫 번째 토론을 시작해 보세요!