이미지 로드시 http => https 변경하여 307리디렉션 제거
This commit is contained in:
@@ -31,19 +31,26 @@ export default memo(function CustomImage({
|
||||
|
||||
useEffect(() => {
|
||||
const _src = Array.isArray(src) ? src[0] : src;
|
||||
if (_src && _src !== imgSrc) {
|
||||
|
||||
// HTTP를 HTTPS로 변환 (HSTS 307 리디렉션 방지)
|
||||
const secureSrc =
|
||||
_src && typeof _src === "string" && _src.startsWith("http://")
|
||||
? _src.replace("http://", "https://")
|
||||
: _src;
|
||||
|
||||
if (secureSrc && secureSrc !== imgSrc) {
|
||||
if (showImageJob.current) {
|
||||
clearTimeout(showImageJob.current);
|
||||
showImageJob.current = null;
|
||||
}
|
||||
setImgSrc(_src);
|
||||
setImgSrc(secureSrc);
|
||||
setError(false);
|
||||
setImageLoaded(false);
|
||||
}
|
||||
if (!_src) {
|
||||
if (!secureSrc) {
|
||||
setError(true);
|
||||
}
|
||||
}, [src]);
|
||||
}, [src, imgSrc]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
@@ -61,13 +68,33 @@ export default memo(function CustomImage({
|
||||
showImageJob.current = setTimeout(() => {
|
||||
setImageLoaded(true);
|
||||
}, delay);
|
||||
|
||||
// 이미지 로드 성공 카운트
|
||||
if (typeof window !== "undefined" && window.__imageLoadStats) {
|
||||
window.__imageLoadStats.success++;
|
||||
window.__imageLoadStats.total++;
|
||||
}
|
||||
|
||||
if (onLoad) onLoad();
|
||||
}, [onLoad, delay]);
|
||||
|
||||
const _onError = useCallback(() => {
|
||||
setError(true);
|
||||
|
||||
// 이미지 로드 실패 카운트
|
||||
if (typeof window !== "undefined" && window.__imageLoadStats) {
|
||||
window.__imageLoadStats.failed++;
|
||||
window.__imageLoadStats.total++;
|
||||
|
||||
// 실패한 이미지 URL 저장
|
||||
if (!window.__imageLoadStats.failedImages) {
|
||||
window.__imageLoadStats.failedImages = [];
|
||||
}
|
||||
window.__imageLoadStats.failedImages.push(imgSrc);
|
||||
}
|
||||
|
||||
if (onError) onError();
|
||||
}, [onError]);
|
||||
}, [onError, imgSrc]);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user