Improve photoswipe loading with data-size
-
Hey there,
if data-size is defined on a-tag you should not load the image because of performance reasons. It’s enough to use the informations from data-size.
For using data-size if available, just change following file:
/photoswipe/jquery.photoswipe.js$target.each(function(){ if( $(this).is('a') ){ $(this).attr(uidkey,uid); var imgSrc = $(this).attr('href'); if( ! ( imgSrc in images ) ){ var img = new Image(); img.src = imgSrc; images[imgSrc] = null; img.onload = function(){ images[imgSrc] = img; }; img.onerror = function(){ images[imgSrc] = img; } } ++uid; } });
to
$target.each(function(){ if( $(this).is('a') ){ $(this).attr(uidkey,uid); var imgSrc = $(this).attr('href'); if( ! ( imgSrc in images ) ){ if( $(this).attr('data-size') ) { var size = $(this).attr('data-size').split('x'); images[imgSrc] = { src: imgSrc, width: size[0], height: size[1] }; } else { var img = new Image(); img.src = imgSrc; images[imgSrc] = null; img.onload = function(){ images[imgSrc] = img; }; img.onerror = function(){ images[imgSrc] = img; } } } ++uid; } });
Best regards
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Improve photoswipe loading with data-size’ is closed to new replies.