mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-02 10:52:27 +00:00
perf: enable lazy loading for avatars and thumbnails
Added `loading="lazy"` and `decoding="async"` attributes to dynamically created `<img>` elements in: - `js/historyView.js` (avatars) - `js/ui/subscriptionHistoryController.js` (channel icons) - `js/searchView.js` (added `decoding="async"`) - `js/ui/profileModal/ProfileDirectMessageRenderer.js` (attachment previews, avatars) - `js/ui/profileModalController.js` (attachment previews, saved profile avatars) This reduces initial page load impact and bandwidth usage by deferring off-screen image loading. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
216361ed77
commit
df62585106
6 files changed
+62
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const filesToCheck = [
|
||||
'js/historyView.js',
|
||||
'js/ui/subscriptionHistoryController.js',
|
||||
'js/searchView.js',
|
||||
'js/ui/profileModal/ProfileDirectMessageRenderer.js',
|
||||
'js/ui/profileModalController.js'
|
||||
];
|
||||
|
||||
let totalImages = 0;
|
||||
let missingLazy = 0;
|
||||
let missingAsync = 0;
|
||||
|
||||
filesToCheck.forEach(file => {
|
||||
const content = fs.readFileSync(file, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (line.includes('createElement("img")') || line.includes("createElement('img')")) {
|
||||
totalImages++;
|
||||
|
||||
// simple heuristic: look ahead next 20 lines for attributes
|
||||
let chunk = lines.slice(i, i + 20).join('\n');
|
||||
|
||||
// Check for variable name
|
||||
const match = line.match(/(?:const|let|var)\s+(\w+)\s*=/);
|
||||
const varName = match ? match[1] : null;
|
||||
|
||||
if (varName) {
|
||||
if (!chunk.includes(`${varName}.loading = "lazy"`)) {
|
||||
missingLazy++;
|
||||
console.log(`[${file}] Missing loading="lazy" for ${varName} at line ${i+1}`);
|
||||
}
|
||||
if (!chunk.includes(`${varName}.decoding = "async"`)) {
|
||||
missingAsync++;
|
||||
console.log(`[${file}] Missing decoding="async" for ${varName} at line ${i+1}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
console.log('--- Results ---');
|
||||
console.log(`Total images found: ${totalImages}`);
|
||||
console.log(`Missing loading="lazy": ${missingLazy}`);
|
||||
console.log(`Missing decoding="async": ${missingAsync}`);
|
||||
Reference in new issue
Block a user