Skip to content

Commit c63187e

Browse files
author
ing
committed
fix(图片压缩工具): 修复错误时机调用revokeObjectURL导致下载失败
1 parent 37a5718 commit c63187e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tools/image-compressor/app.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ <h1>图片压缩工具</h1>
222222
const downloadLink = document.getElementById('download');
223223
let image = new Image();
224224
let originalSize = 0;
225+
let currentBlobUrl = null;
225226

226227
function formatBytes(bytes) {
227228
if (!bytes) return '--';
@@ -280,9 +281,13 @@ <h1>图片压缩工具</h1>
280281
}, format, quality);
281282
}
282283
}).then((blob) => {
284+
// 释放之前的 blob URL
285+
if (currentBlobUrl) {
286+
URL.revokeObjectURL(currentBlobUrl);
287+
}
283288
const url = URL.createObjectURL(blob);
289+
currentBlobUrl = url;
284290
const previewImg = new Image();
285-
previewImg.onload = () => URL.revokeObjectURL(url);
286291
previewImg.src = url;
287292
preview.innerHTML = '';
288293
preview.appendChild(previewImg);

0 commit comments

Comments
 (0)