Spaces:
Running
Running
perf: Improve image loading with fragment and async decoding
Browse files- index.html +6 -4
index.html
CHANGED
|
@@ -52,15 +52,15 @@
|
|
| 52 |
const screenshots = await response.json();
|
| 53 |
const grid = document.getElementById('screenshot-grid');
|
| 54 |
grid.innerHTML = ''; // Clear existing content
|
|
|
|
| 55 |
|
| 56 |
-
// Filter out non-png files just in case
|
| 57 |
// Filter out non-png files just in case
|
| 58 |
const imageFiles = screenshots.filter(file => file.endsWith('.png'));
|
| 59 |
|
| 60 |
// Sort images in reverse alphabetical order
|
| 61 |
imageFiles.sort().reverse();
|
| 62 |
|
| 63 |
-
//
|
| 64 |
imageFiles.forEach(filename => {
|
| 65 |
const gridItem = document.createElement('div');
|
| 66 |
gridItem.className = 'grid-item';
|
|
@@ -70,6 +70,7 @@
|
|
| 70 |
img.src = `screenshots/${filename}`;
|
| 71 |
img.alt = filename;
|
| 72 |
img.loading = 'lazy'; // Lazy load images
|
|
|
|
| 73 |
|
| 74 |
// Create the link element
|
| 75 |
const link = document.createElement('a');
|
|
@@ -105,10 +106,11 @@
|
|
| 105 |
|
| 106 |
link.appendChild(img); // Place the image inside the link
|
| 107 |
gridItem.appendChild(link); // Place the link (with image) inside the grid item
|
| 108 |
-
|
| 109 |
});
|
| 110 |
|
| 111 |
-
//
|
|
|
|
| 112 |
|
| 113 |
} catch (error) {
|
| 114 |
console.error('Failed to load screenshots:', error);
|
|
|
|
| 52 |
const screenshots = await response.json();
|
| 53 |
const grid = document.getElementById('screenshot-grid');
|
| 54 |
grid.innerHTML = ''; // Clear existing content
|
| 55 |
+
const fragment = document.createDocumentFragment(); // Create a fragment
|
| 56 |
|
|
|
|
| 57 |
// Filter out non-png files just in case
|
| 58 |
const imageFiles = screenshots.filter(file => file.endsWith('.png'));
|
| 59 |
|
| 60 |
// Sort images in reverse alphabetical order
|
| 61 |
imageFiles.sort().reverse();
|
| 62 |
|
| 63 |
+
// Build elements in the fragment
|
| 64 |
imageFiles.forEach(filename => {
|
| 65 |
const gridItem = document.createElement('div');
|
| 66 |
gridItem.className = 'grid-item';
|
|
|
|
| 70 |
img.src = `screenshots/${filename}`;
|
| 71 |
img.alt = filename;
|
| 72 |
img.loading = 'lazy'; // Lazy load images
|
| 73 |
+
img.decoding = 'async'; // Hint for async decoding
|
| 74 |
|
| 75 |
// Create the link element
|
| 76 |
const link = document.createElement('a');
|
|
|
|
| 106 |
|
| 107 |
link.appendChild(img); // Place the image inside the link
|
| 108 |
gridItem.appendChild(link); // Place the link (with image) inside the grid item
|
| 109 |
+
fragment.appendChild(gridItem); // Add the item to the fragment
|
| 110 |
});
|
| 111 |
|
| 112 |
+
// Append the fragment to the grid once
|
| 113 |
+
grid.appendChild(fragment);
|
| 114 |
|
| 115 |
} catch (error) {
|
| 116 |
console.error('Failed to load screenshots:', error);
|