feat(perf): implement comprehensive Core Web Vitals, ISR caching, and media optimizations
Deploy Canina / deploy (push) Successful in 1m48s
Deploy Canina / deploy (push) Successful in 1m48s
This commit is contained in:
1 parent
2a31a9f8e4
commit
fe6a900665
42 files changed
+12941
-10561
No files matched your search
@@ -128,7 +128,13 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
)}
|
||||
|
||||
<div className="aspect-square bg-medical-gray-50 flex items-center justify-center p-8 overflow-hidden relative">
|
||||
<SafeImage src={product.image} alt={product.name} className="w-full h-full group-hover:scale-110 transition-transform duration-700" imgClassName="object-contain" />
|
||||
<SafeImage
|
||||
src={product.image}
|
||||
alt={product.name}
|
||||
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 25vw)"
|
||||
className="w-full h-full group-hover:scale-110 transition-transform duration-700"
|
||||
imgClassName="object-contain"
|
||||
/>
|
||||
<div className="absolute bottom-4 left-4 flex gap-2">
|
||||
{(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm">
|
||||
|
||||
@@ -245,6 +245,8 @@ export default function BlogPage({
|
||||
src={featuredPost.image}
|
||||
alt={featuredPost.imageAlt || featuredPost.title}
|
||||
fill
|
||||
priority
|
||||
sizes="(max-width: 1024px) 100vw, 50vw"
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-700"
|
||||
unoptimized
|
||||
/>
|
||||
@@ -314,6 +316,7 @@ export default function BlogPage({
|
||||
src={post.image}
|
||||
alt={post.imageAlt || post.title}
|
||||
fill
|
||||
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
|
||||
className="w-full h-full object-cover group-hover:scale-108 transition-transform duration-700"
|
||||
unoptimized
|
||||
/>
|
||||
|
||||
@@ -122,11 +122,13 @@ export default function BlogPreviewSection() {
|
||||
transition={{ delay: idx * 0.1 }}
|
||||
className="bg-medical-gray-50/60 rounded-[2rem] border border-medical-gray-100 overflow-hidden hover:shadow-lg hover:-translate-y-1 transition-all flex flex-col group"
|
||||
>
|
||||
<Link href={`/blog/${blog.slug}`} className="block relative h-52 overflow-hidden bg-medical-gray-100">
|
||||
<Link href={`/blog/${blog.slug}`} className="block relative aspect-video w-full overflow-hidden bg-medical-gray-100">
|
||||
<SafeImage
|
||||
src={image}
|
||||
alt={blog.title}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"
|
||||
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
|
||||
className="w-full h-full"
|
||||
imgClassName="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"
|
||||
/>
|
||||
</Link>
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ function ProductCard({ product }: { product: Product }) {
|
||||
<SafeImage
|
||||
src={product.image}
|
||||
alt={nameFa}
|
||||
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 25vw)"
|
||||
className="w-full h-full group-hover:scale-105 transition-transform duration-500"
|
||||
imgClassName="object-contain max-h-[170px] mx-auto"
|
||||
/>
|
||||
|
||||
@@ -184,6 +184,7 @@ export default function PodcastInlinePlayer({ podcast }: PodcastInlinePlayerProp
|
||||
<audio
|
||||
ref={audioRef}
|
||||
src={podcast.audioUrl}
|
||||
preload="none"
|
||||
onPlay={() => setIsPlaying(true)}
|
||||
onPause={() => setIsPlaying(false)}
|
||||
onTimeUpdate={() => {
|
||||
|
||||
@@ -65,12 +65,14 @@ const useCalculatorStore = create<CalculatorState>((set) => ({
|
||||
setWeight: (weight) => set({ weight }),
|
||||
}));
|
||||
|
||||
import dynamic from 'next/dynamic';
|
||||
import Tooltip from "./Tooltip";
|
||||
import SafeImage from "./SafeImage";
|
||||
import ProductReviews from "./ProductReviews";
|
||||
import VideoModalPlayer from "./VideoModalPlayer";
|
||||
import PodcastInlinePlayer from "./PodcastInlinePlayer";
|
||||
|
||||
const VideoModalPlayer = dynamic(() => import("./VideoModalPlayer"), { ssr: false });
|
||||
const ProductReviews = dynamic(() => import("./ProductReviews"), { ssr: false });
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
@@ -293,6 +295,8 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
<SafeImage
|
||||
src={activeImage || product.image}
|
||||
alt={product.name}
|
||||
priority={true}
|
||||
sizes="(max-width: 768px) 100vw, 400px"
|
||||
className="w-full h-full"
|
||||
imgClassName="max-h-[240px] sm:max-h-[300px] w-auto object-contain drop-shadow-2xl group-hover:scale-105 transition-transform duration-700 mx-auto my-auto"
|
||||
/>
|
||||
|
||||
@@ -10,6 +10,11 @@ interface SafeImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>,
|
||||
className?: string;
|
||||
imgClassName?: string;
|
||||
fallbackText?: string;
|
||||
priority?: boolean;
|
||||
sizes?: string;
|
||||
quality?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
}
|
||||
|
||||
export default function SafeImage({
|
||||
@@ -17,10 +22,15 @@ export default function SafeImage({
|
||||
alt = "تصویر مکمل کنینا",
|
||||
className,
|
||||
imgClassName,
|
||||
fallbackText = "در حال بروزرسانی تصویر..."
|
||||
fallbackText = "در حال بروزرسانی تصویر...",
|
||||
priority = false,
|
||||
sizes = "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 400px",
|
||||
quality = 85,
|
||||
width = 500,
|
||||
height = 500,
|
||||
}: SafeImageProps) {
|
||||
const [error, setError] = React.useState(false);
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [loading, setLoading] = React.useState(!priority);
|
||||
|
||||
// Check if external domain is in allowed remote patterns or relative path
|
||||
const isExternal = typeof src === 'string' && (src.startsWith('http://') || src.startsWith('https://'));
|
||||
@@ -43,7 +53,7 @@ export default function SafeImage({
|
||||
if (!src || error) {
|
||||
return (
|
||||
<div className={cn(
|
||||
"flex flex-col items-center justify-center bg-medical-gray-50/90 border border-medical-gray-100 p-2 text-center w-full h-full rounded-2xl relative overflow-hidden select-none",
|
||||
"flex flex-col items-center justify-center bg-medical-gray-50/90 border border-medical-gray-100 p-2 text-center w-full h-full rounded-2xl relative overflow-hidden select-none aspect-square",
|
||||
className
|
||||
)}>
|
||||
<Image
|
||||
@@ -63,7 +73,7 @@ export default function SafeImage({
|
||||
|
||||
return (
|
||||
<div className={cn("relative overflow-hidden group flex items-center justify-center", className)}>
|
||||
{loading && (
|
||||
{loading && !priority && (
|
||||
<div className="absolute inset-0 bg-medical-gray-50 animate-pulse flex items-center justify-center z-10">
|
||||
<Sparkles className="w-6 h-6 text-canina-blue/20" />
|
||||
</div>
|
||||
@@ -71,14 +81,17 @@ export default function SafeImage({
|
||||
<Image
|
||||
src={src}
|
||||
alt={alt}
|
||||
width={500}
|
||||
height={500}
|
||||
loading="lazy"
|
||||
width={width}
|
||||
height={height}
|
||||
priority={priority}
|
||||
loading={priority ? undefined : "lazy"}
|
||||
sizes={sizes}
|
||||
quality={quality}
|
||||
unoptimized={isBlobOrData || !isAllowedHost}
|
||||
className={cn(
|
||||
"transition-all duration-700 w-full h-full",
|
||||
"transition-all duration-500 w-full h-full object-contain",
|
||||
imgClassName,
|
||||
loading ? "opacity-0 scale-110" : "opacity-100 scale-100"
|
||||
loading && !priority ? "opacity-0 scale-105" : "opacity-100 scale-100"
|
||||
)}
|
||||
onLoad={() => setLoading(false)}
|
||||
onError={() => setError(true)}
|
||||
|
||||
Reference in new issue
Block a user