Skip to content

Commit 3f3ac4d

Browse files
committed
- avoid lazy-loading above-the-fold images
1 parent ea55ed0 commit 3f3ac4d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

index.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ <h3>No results found</h3>
281281
const gridViewBtn = document.getElementById('gridViewBtn');
282282
const listViewBtn = document.getElementById('listViewBtn');
283283
const statsContainer = document.getElementById('statsContainer');
284+
const isMobile = navigator.userAgentData?.mobile ?? /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
284285

285286
// State
286287
let allItems = [];
@@ -323,14 +324,18 @@ <h3>No results found</h3>
323324
}
324325

325326
// Create card HTML
326-
function createCard(item) {
327+
function createCard(item, index) {
327328
const isNew = isNewItem(item);
328329
const cardClass = `card ${item.type}${isListView ? ' list-card' : ''}`;
329330

331+
let numberOfLazyLoads = isMobile ? 4 : 10;
332+
const shouldLazyLoad = index >= numberOfLazyLoads;
333+
const loadingAttribute = shouldLazyLoad ? 'loading="lazy"' : 'fetchpriority="high"';
334+
330335
return `
331336
<div class="${cardClass}" data-id="${item.id}" data-type="${item.type}" data-category="${getCategory(item)}">
332337
<div class="card-img-wrap">
333-
<img src="${item.screenshot}" alt="${item.title}" class="card-img" loading="lazy">
338+
<img src="${item.screenshot}" alt="${item.title}" class="card-img" ${loadingAttribute}>
334339
<span class="card-type ${item.type}">${item.type}</span>
335340
<div class="card-badges">
336341
${item.aiPowered ? '<span class="card-badge">AI Powered</span>' : ''}
@@ -446,7 +451,7 @@ <h3 class="card-title" title="${item.title}">${item.title}</h3>
446451
const itemsToShow = filtered.slice(0, end);
447452

448453
mainGrid.className = isListView ? 'list-view' : 'grid-view';
449-
mainGrid.innerHTML = itemsToShow.map(createCard).join('');
454+
mainGrid.innerHTML = itemsToShow.map((item, index) => createCard(item, index)).join('');
450455

451456
document.querySelectorAll('.read-more').forEach(btn => {
452457
btn.addEventListener('click', function() {

0 commit comments

Comments
 (0)