From cfc06e10d02d2527b72b6af1e17bab1b3a27d1a2 Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Wed, 23 Feb 2022 14:48:32 +0100 Subject: [PATCH] Improve dynamic cache generation --- src/assets/js/wishlist-view.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/assets/js/wishlist-view.js b/src/assets/js/wishlist-view.js index 5158f001..8be8726b 100644 --- a/src/assets/js/wishlist-view.js +++ b/src/assets/js/wishlist-view.js @@ -56,7 +56,7 @@ $(function() { /** * Generate cache */ - var timerInterval = 200; + var timerInterval = 1200; var timerCache = setTimeout( function generateCache() { var cards = $('.ui.card[data-cache="false"]'); @@ -68,6 +68,7 @@ $(function() { var product_id = card.data('id'); card.addClass('loading'); + card.attr('data-cache', true); fetch('/src/api/cache.php?product_id=' + product_id + '&url=' + href, { method: 'GET' @@ -168,19 +169,20 @@ $(function() { /** * Finish */ - card.attr('data-cache', true); card.removeClass('loading'); - - if (cards.length > 0) { - setTimeout(generateCache, timerInterval); - } } }); - return false; + if (index >= 0) { + return false; + } }); + + if (cards.length > 0) { + setTimeout(generateCache, timerInterval); + } }, - timerInterval + 0 ); });