diff --git a/src/imgix-core-js.js b/src/imgix-core-js.js index 56398af9b..2f9bf01f5 100644 --- a/src/imgix-core-js.js +++ b/src/imgix-core-js.js @@ -224,10 +224,15 @@ // returns an array of width values used during scrset generation ImgixClient.prototype._generateTargetWidths = function(widthTolerance, minWidth, maxWidth) { - var resolutions = []; + var resolutions = [minWidth]; var INCREMENT_PERCENTAGE = widthTolerance; var minWidth = Math.floor(minWidth); var maxWidth = Math.floor(maxWidth); + + if (minWidth === maxWidth) { + return resolutions; + } + var cacheKey = INCREMENT_PERCENTAGE + '/' + minWidth + '/' + maxWidth; if (cacheKey in this.targetWidthsCache) { @@ -238,14 +243,12 @@ return 2 * Math.round(n / 2); }; - var prev = minWidth; - while (prev < maxWidth) { - resolutions.push(ensureEven(prev)); - prev *= 1 + (INCREMENT_PERCENTAGE * 2); + var exact = minWidth; + while (resolutions[resolutions.length - 1] < maxWidth) { + exact *= 1 + (INCREMENT_PERCENTAGE * 2); + resolutions.push(Math.min(ensureEven(exact), maxWidth)); } - resolutions.push(maxWidth); - this.targetWidthsCache[cacheKey] = resolutions; return resolutions;