Home Forums Front-end Issues Very slow TTFB with repeater gallery


Very slow TTFB with repeater gallery

  • Hi
    I have created a gallery with a lightbox.
    The page has a very slow TTDB (time to firs byte).
    It happens only on this page. When I remove the gallery code the page loads quickly.
    This is the code:

      <ul style="clear:both; overflow:auto;" class="album-gallery">
    	if( have_rows( 'mygallery' ) )  :  $j=1; ?>
                while( have_rows( 'mygallery' ) ) : the_row(); 
    			<?php if( get_sub_field('featured_image') ) { ?>
    				<li class="featured-product-frame archive_dj_thumb_holder clear dj_item_inner">
     $images = get_sub_field('gallery');                 
     $imageArray = get_sub_field('featured_image'); // Array returned by Advanced Custom Fields
     $imageAlt = $imageArray['alt']; // Grab, from the array, the 'alt'
     $imageURL = $imageArray['url']; // Grab the full size version 
     $imageThumbURL = $imageArray['sizes']['archive_dj_thumb']; //grab from the array, the 'sizes', and from it, the 'thumbnail'
     <a href="<?php echo $imageURL; ?>"   data-group="lightbox-<?php echo $j; ?>"  class="html5lightbox fancybox image" >
        <img src="<?php echo $imageThumbURL;?>" alt="<?php echo $imageAlt; ?>">
    <div style="text-align:center; padding-top:15px" class="album-name"><?php the_sub_field('album_name'); ?></div>
                    <?php if( $images ): ?>
        <ul style="display:none;">
            <?php foreach( $images as $image ): ?>
                    <a href="<?php echo $image['url']; ?>"   data-group="lightbox-<?php echo $j; ?>" class="html5lightbox fancybox image" >
                    <p><?php echo $image['caption']; ?></p>
            <?php endforeach; ?>
    <?php endif; ?>
    			<?php } ?>
            <?php $j+=1; endwhile; wp_reset_postdata(); ?>
    	<?php endif; ?>

    Am I doing something wrong causing this bug?

  • I was told by support that the cause of this might be because of the counter being inside the acf loop
    How can I remove the counter from the loop and still have it function for the lightboxes to work?


  • I know this is a couple or 3 months old and not sure if you found a resolution or not, but, I doubt a simple counter j=1; j+=1 would have anything to do with it. I would change it to j++, although that should not effect anything.

    The main issue is most likely the image and gallery fields returning the image arrays. The more image sizes you have on the site the slower this is going to be.

    When it comes to image fields, if you’re worried about performance, you are better off either returning just the ID for each image or getting the unformatted value from ACF and then using core WP functions to get the only the information you need about each image. The image array is going to have a lot of image data that you’ll never use.

    You can get unformatted data from ACF by supplying false as the 3rd argument get_field('field_name, false, false);` the second false gets values for the current post.

    use wp_get_attachment_image_src($image_id, $size); to get the image info.
    use get_post_meta($image_id, '_wp_attachment_image_alt', true); to get the alt text.
    use get_post_field('post_excerpt', $image_id); to get the caption

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Very slow TTFB with repeater gallery’ is closed to new replies.