我正在编写一个从S3存储桶下载图像库的网站。问题是上传到存储桶的图像可能非常大,这可能导致图库中的性能不佳。我目前正在使用简单的Javascript来浏览我的S3 URL数组,并且每隔几秒就更改幻灯片图像的源代码。我还按顺序预加载图像,以便缓存它们并提高性能:
function preload(imageArray, index) {
index = index || 0;
if (imageArray && imageArray.length > index) {
var img = new Image ();
img.onload = function() {
console.log("Preloaded: ", img.src)
preload(imageArray, index + 1);
}
img.src = imageArray[index];
}
}
限制从S3存储桶下载的图像的文件大小的最佳做法是什么?我会在预加载中执行此操作,还是会设置图库的img
元素的属性?