Preload classic layout CSS before the blocking head loader

This commit is contained in:
Jonathan Sykes
2026-10-08 08:50:51 +08:00
parent 799b1e7ed6
commit e7a7cdc6b9
3 changed files with 15 additions and 2 deletions

View File

@@ -70,6 +70,8 @@ test('only core scripts and styles remain eager; native fallback and active layo
const {groups}=JSON.parse(readFileSync(join(__dirname,'assets.json'),'utf8'));
const background=new Set(Object.values(groups).filter(g=>g.background).flatMap(g=>g.files));
for(const match of html.matchAll(/<(?:script\b[^>]*\bsrc|link\b[^>]*\bhref)="([^"]+)"/gi)) {
// A style preload discovers bytes without applying or blocking another layout.
if(match[0].includes('rel="preload"'))continue;
const path='/'+match[1].replace(/^\//,'').split(/[?#]/)[0];
assert.ok(!background.has(path),`${path} is not eager`);
}
@@ -88,3 +90,11 @@ test('layout-independent visibility and transport defaults stay in eager CSS',()
for(const selector of ['.stg-overlay','.deck-chips','.np-btn.done .i-save','.sleep-status .sl-ic','.ab-group','.mc-tune'])assert.ok(shared.includes(selector));
assert.ok(html.includes('href="layout-base.css"'));
});
test('classic first-visit style preload is discovered before the head loader without applying another layout',()=>{
const preload=html.match(/<link\b[^>]*rel="preload"[^>]*href="theme-classic.css"[^>]*as="style"[^>]*>/);
assert.ok(preload,'classic stylesheet has an early preload');
assert.ok(html.indexOf(preload[0])<html.indexOf('src="lazy.js"'));
assert.ok(!/<link\b[^>]*rel="stylesheet"[^>]*href="theme-classic.css"/.test(html),'the selected layout remains parser-applied by the loader');
});