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