Skip to content

Commit 6c898c6

Browse files
authored
Limit responsive image URLs (#143)
* Limit responsive image URLs * Restrict to data: URLs
1 parent 21e084c commit 6c898c6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dist/responsive_images.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ function intrinsicOrExtrinsicSizing( computedStyles ) {
305305
function getImgData( img ) {
306306

307307
const imgData = imgFeatures( img );
308-
imgData.url = img.currentSrc || img.src;
308+
// Limit data URLs so they don't take up huge amounts of space.
309+
imgData.url =
310+
(img.currentSrc || img.src)?.startsWith('data:') && (img.currentSrc || img.src)?.length > 50 ?
311+
(img.currentSrc || img.src)?.slice(0, 50) + '…' :
312+
(img.currentSrc || img.src);
309313
imgData.totalCandidates = totalNumberOfCandidates( img );
310314

311315
if (imgData.hasHeight) {
@@ -358,7 +362,10 @@ function getImgData( img ) {
358362
!isFromSource &&
359363
!( imgData.srcsetHasWDescriptors ) ) {
360364
srcsetCandidates.push( {
361-
url: img.getAttribute( 'src' )
365+
// Limit data URLs so they don't take up huge amounts of space.
366+
url: img.getAttribute( 'src' )?.startsWith('data:') && img.getAttribute( 'src' )?.length > 50 ?
367+
img.getAttribute( 'src' )?.slice(0, 50) + '…' :
368+
img.getAttribute( 'src' )
362369
} )
363370
}
364371

0 commit comments

Comments
 (0)