Files
voculinux/web/src/components/optimized-image.tsx
T
Jatin K MalikandGitHub 0d9c488d82 fix: optimize PageSpeed Insights performance (#115)
* fix: optimize PageSpeed Insights performance

This commit addresses several PageSpeed Insights issues to improve
the performance score from 56 to a target of 90+.

Changes:
- Add SWC config to output modern ES2022 JavaScript, eliminating
  unnecessary polyfills (~12 KiB savings)
- Convert vocalinux.png to WebP format (17KB vs 207KB - 92% reduction)
- Add OptimizedImage component with WebP/PNG fallback support
- Add _headers file for proper static asset caching (1 year cache
  for immutable assets)
- Configure Next.js with optimizePackageImports for framer-motion
  and lucide-react
- Fix heading hierarchy issue (Quick Install h3 -> h2)
- Add console.log removal in production builds

Expected improvements:
- Image delivery: ~41 KiB savings
- Legacy JavaScript: ~12 KiB savings
- Cache lifetime: 754 KiB proper caching
- Accessibility score: 98 -> 100 (heading order fix)

* test: add coverage for PageSpeed optimization

Add comprehensive test suite for PageSpeed Insights optimization changes:

- WebP image loading tests (optimized-image.tsx)
- next/image component configuration tests (next.config.js)
- _headers file generation and cache header tests
- Lazy loading behavior tests

Includes:
- Jest configuration with TypeScript support
- React Testing Library setup
- 54 test cases covering all PageSpeed optimization features
- Build verification

All tests pass: npm run test
Build passes: npm run build

* ci: trigger workflow

* ci: trigger workflow run

* ci: trigger workflow
2026-02-04 19:25:34 -08:00

71 lines
1.6 KiB
TypeScript

"use client";
import React, { useState } from "react";
import Image from "next/image";
interface OptimizedImageProps {
src: string;
alt: string;
width: number;
height: number;
className?: string;
priority?: boolean;
}
/**
* Optimized image component that uses WebP format with PNG fallback.
* Browsers that support WebP will load the smaller WebP file, while older
* browsers will fallback to PNG format.
*/
export const OptimizedImage: React.FC<OptimizedImageProps> = ({
src,
alt,
width,
height,
className = "",
priority = false,
}) => {
// Get WebP version of the image
const webpSrc = src.replace(/\.(png|jpg|jpeg)$/i, '.webp');
// For Next.js Image component with priority and proper optimization
// we use the Next.js Image with WebP source
return (
<picture className={className}>
<source srcSet={webpSrc} type="image/webp" />
<Image
src={src}
alt={alt}
width={width}
height={height}
className={className}
priority={priority}
/>
</picture>
);
};
/**
* Specialized Vocalinux logo component with WebP support
*/
export const VocalinuxLogo: React.FC<{
className?: string;
width?: number;
height?: number;
priority?: boolean;
}> = ({ className = "", width = 32, height = 32, priority = false }) => {
return (
<picture className={className}>
<source srcSet="/vocalinux.webp" type="image/webp" />
<Image
src="/vocalinux.png"
alt="Vocalinux"
width={width}
height={height}
className={className}
priority={priority}
/>
</picture>
);
};