Skip to content

Commit 2be82b6

Browse files
authored
Merge pull request #70 from nucliweb/consistency-ci-docs
Refine Loading snippets consistency
2 parents ad542c2 + c8cfbd8 commit 2be82b6

20 files changed

Lines changed: 98 additions & 58 deletions

scripts/generate-skills.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,6 @@ function extractThresholds(content) {
218218
return ''
219219
}
220220

221-
// Strip internal relative links (e.g. /CoreWebVitals/LCP-Sub-Parts) from markdown link text
222-
function cleanLinks(text) {
223-
return text
224-
.replace(/\[([^\]]+)\]\(\/[^)]+\)/g, '$1') // remove internal links, keep text
225-
.replace(/\[([^\]]+)\]\((https?:[^)]+)\)/g, '[$1]($2)') // keep external links
226-
}
227-
228221
// Build metadata for a single snippet JS file
229222
function buildSnippetMeta(category, snippetFile) {
230223
const basename = path.basename(snippetFile, '.js')

scripts/install-global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function main() {
2525
console.log('1️⃣ Generating skills...')
2626
try {
2727
execSync('node scripts/generate-skills.js', { cwd: ROOT, stdio: 'inherit' })
28-
} catch (error) {
28+
} catch {
2929
console.error('❌ Failed to generate skills')
3030
process.exit(1)
3131
}

scripts/install-skills.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function main() {
2626
console.log('1️⃣ Generating skills...')
2727
try {
2828
execSync('node scripts/generate-skills.js', { cwd: ROOT, stdio: 'inherit' })
29-
} catch (error) {
29+
} catch {
3030
console.error('❌ Failed to generate skills')
3131
process.exit(1)
3232
}

snippets/Loading/Back-Forward-Cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@
412412

413413
// Initialize
414414
checkRestoration();
415-
const eligibility = testEligibility();
415+
testEligibility();
416416

417417
// Display after a short delay to ensure pageshow event fires
418418
setTimeout(() => {

snippets/Loading/CSS-Media-Queries-Analysis.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ async function analyzeCSSMediaQueries(minWidth = 768) {
142142
}
143143
});
144144
}
145-
} catch (e) {
145+
} catch {
146146
// If CORS blocked, try to fetch the CSS
147147
if (sheet.href) {
148148
try {
149149
const response = await fetch(sheet.href);
150150
const cssText = await response.text();
151151
parseMediaQueriesFromCSS(cssText, sheet.href, false);
152-
} catch (fetchError) {
152+
} catch {
153153
// Silently count CORS blocked files
154154
corsBlockedCount++;
155155
}
@@ -485,6 +485,8 @@ async function analyzeCSSPerformanceImpact(minWidth = 768) {
485485
};
486486
}
487487

488+
window.analyzeCSSPerformanceImpact = analyzeCSSPerformanceImpact;
489+
488490
// Run with default breakpoint (768px)
489491
(async () => {
490492
const result = await analyzeCSSMediaQueries();

snippets/Loading/Client-Side-Redirect-Detection.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@
207207
// Recommendations
208208
const hasDocumentNavigation = documentNavigations.length > 0;
209209
const hasSameOriginRedirect = sameOrigin && referrerPath !== currentPath && referrerPath !== '';
210-
const hasHighImpact = hasDocumentNavigation && documentNavigations.reduce((sum, nav) => sum + nav.duration, 0) > 1000;
211-
212210
if (hasDocumentNavigation || serverRedirects > 0) {
213211
console.log('');
214212
console.log('%c💡 Recommendations:', 'font-weight: bold;');

snippets/Loading/Content-Visibility.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function detectContentVisibility() {
3636
if (el.id) break;
3737
node = el.parentNode;
3838
}
39-
} catch (err) {
39+
} catch {
4040
// Do nothing...
4141
}
4242
return sel;
@@ -188,7 +188,7 @@ function analyzeContentVisibilityOpportunities(options = {}) {
188188
if (el.id) break;
189189
node = el.parentNode;
190190
}
191-
} catch (err) {}
191+
} catch {}
192192
return sel;
193193
}
194194

@@ -271,7 +271,13 @@ function analyzeContentVisibilityOpportunities(options = {}) {
271271
console.log("");
272272

273273
// Show table without element reference
274-
const tableData = opportunities.slice(0, 20).map(({ element, ...rest }) => rest);
274+
const tableData = opportunities.slice(0, 20).map((opportunity) => ({
275+
selector: opportunity.selector,
276+
height: opportunity.height,
277+
distanceFromViewport: opportunity.distanceFromViewport,
278+
childElements: opportunity.childElements,
279+
estimatedSavings: opportunity.estimatedSavings,
280+
}));
275281
console.table(tableData);
276282

277283
if (opportunities.length > 20) {
@@ -304,13 +310,21 @@ function analyzeContentVisibilityOpportunities(options = {}) {
304310
console.groupEnd();
305311

306312
return {
307-
opportunities: opportunities.map(({ element, ...rest }) => rest),
313+
opportunities: opportunities.map((opportunity) => ({
314+
selector: opportunity.selector,
315+
height: opportunity.height,
316+
distanceFromViewport: opportunity.distanceFromViewport,
317+
childElements: opportunity.childElements,
318+
estimatedSavings: opportunity.estimatedSavings,
319+
})),
308320
totalElements: opportunities.length,
309321
highImpact: opportunities.filter((o) => o.estimatedSavings.startsWith("High")).length,
310322
elements: opportunities.map((o) => o.element),
311323
};
312324
}
313325

326+
window.analyzeContentVisibilityOpportunities = analyzeContentVisibilityOpportunities;
327+
314328
// Run detection
315329
(() => {
316330
const cvResults = detectContentVisibility();

snippets/Loading/Critical-CSS-Detection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
(s) => s.href === href
5858
);
5959
if (sheet && sheet.cssRules) ruleCount = sheet.cssRules.length;
60-
} catch (_) {
60+
} catch {
6161
corsBlocked = true;
6262
}
6363

snippets/Loading/Find-Above-The-Fold-Lazy-Loaded-Images.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if (el.id) break;
2020
node = el.parentNode;
2121
}
22-
} catch (err) {}
22+
} catch {}
2323
return sel;
2424
}
2525

@@ -54,7 +54,7 @@
5454
if (entry && entry.transferSize) {
5555
return (entry.transferSize / 1024).toFixed(1) + " KB";
5656
}
57-
} catch (err) {}
57+
} catch {}
5858
return null;
5959
}
6060

@@ -189,10 +189,19 @@
189189

190190
// Table of all problematic images
191191
console.group("📋 Lazy Loaded Images in Viewport");
192-
const tableData = results.lazyImages.map(({ element, area, position, ...rest }) => ({
193-
...rest,
194-
top: position.top + "px",
195-
isLcpCandidate: rest.isLcpCandidate ? "⚠️ YES" : "no"
192+
const tableData = results.lazyImages.map((image) => ({
193+
selector: image.selector,
194+
lazyType: image.lazyType,
195+
dimensions: image.dimensions,
196+
top: image.position.top + "px",
197+
distanceFromEdge: image.distanceFromEdge,
198+
src: image.src,
199+
srcset: image.srcset,
200+
sizes: image.sizes,
201+
alt: image.alt,
202+
fetchPriority: image.fetchPriority,
203+
fileSize: image.fileSize,
204+
isLcpCandidate: image.isLcpCandidate ? "⚠️ YES" : "no",
196205
}));
197206
console.table(tableData);
198207
console.groupEnd();
@@ -233,7 +242,20 @@
233242
withDataSrc: results.summary.withDataSrc,
234243
lcpAffected: results.summary.lcpAffected,
235244
},
236-
items: results.lazyImages.map(({ element, area, ...rest }) => rest),
245+
items: results.lazyImages.map((image) => ({
246+
selector: image.selector,
247+
lazyType: image.lazyType,
248+
dimensions: image.dimensions,
249+
position: image.position,
250+
distanceFromEdge: image.distanceFromEdge,
251+
src: image.src,
252+
srcset: image.srcset,
253+
sizes: image.sizes,
254+
alt: image.alt,
255+
fetchPriority: image.fetchPriority,
256+
fileSize: image.fileSize,
257+
isLcpCandidate: image.isLcpCandidate,
258+
})),
237259
issues: [
238260
...(results.summary.lcpAffected ? [{ severity: "error", message: 'LCP candidate image has lazy loading — remove loading="lazy" and add fetchpriority="high"' }] : []),
239261
...(results.lazyImages.filter(i => !i.isLcpCandidate).length > 0 ? [{ severity: "warning", message: `${results.lazyImages.filter(i => !i.isLcpCandidate).length} above-fold image(s) have lazy loading — remove loading="lazy"` }] : []),

snippets/Loading/Find-Images-With-Lazy-and-Fetchpriority.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
if (el.id) break;
2020
node = el.parentNode;
2121
}
22-
} catch (err) {}
22+
} catch {}
2323
return sel;
2424
}
2525

@@ -87,12 +87,18 @@
8787
});
8888

8989
console.log("%c📋 Conflicting Elements:", "font-weight: bold;");
90-
console.table(tableData.map(({ element, ...rest }) => rest));
90+
console.table(tableData.map((item) => ({
91+
selector: item.selector,
92+
dimensions: item.dimensions,
93+
inViewport: item.inViewport,
94+
isLcpCandidate: item.isLcpCandidate,
95+
src: item.src,
96+
})));
9197

9298
// Elements for inspection
9399
console.log("");
94100
console.log("%c🔎 Elements for inspection:", "font-weight: bold;");
95-
tableData.forEach(({ element, selector, isLcpCandidate }, i) => {
101+
tableData.forEach(({ element, isLcpCandidate }, i) => {
96102
const marker = isLcpCandidate === "⚠️ Yes" ? " 🚨 LCP" : "";
97103
console.log(`${i + 1}.${marker}`, element);
98104
});

0 commit comments

Comments
 (0)