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
@@ -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