perf: load page modules on demand and avoid repeated startup ACL writes

This commit is contained in:
abaishu0730 committed 2026-10-28 15:20:28 +08:00
1 parent 73773f9526
commit 7ead1e7cb7
19 files changed
+330 -24

No files matched your search

+11 -1
View File
@@ -56,11 +56,21 @@ test('asset URLs become immutable only when their content fingerprint is verifie
test('HTML uses actual fingerprint URLs while the document itself always revalidates',async t=>{
const get=await fixture(t),page=await get('/'),html=page.bytes.toString();
const urls=[...html.matchAll(/(?:src|href)="(\/[^"#]+)"/g)].map(match=>match[1]);assert.ok(urls.length>=44);
const urls=[...html.matchAll(/(?:src|href)="(\/[^"#]+)"/g)].map(match=>match[1]);assert.ok(urls.length>0&&urls.length<20,'core shell stays below twenty eager assets');
for(const url of urls){assert.match(url,/\?v=[a-f0-9]{64}$/);const asset=await get(url);assert.equal(asset.status,200);assert.match(asset.headers['cache-control'],/immutable/);assert.equal(new URL(url,'http://local').searchParams.get('v'),asset.headers['x-asset-version']);}
const versioned=await get('/?v='+page.headers['x-asset-version']);assert.match(versioned.headers['cache-control'],/must-revalidate/);assert.doesNotMatch(versioned.headers['cache-control'],/immutable/);
});
test('HTML publishes fingerprint URLs for lazy modules without eagerly loading optional pages',async t=>{
const get=await fixture(t),page=await get('/'),html=page.bytes.toString();
const encoded=/<meta name="app-modules" content="([^"]+)"/.exec(html)?.[1];assert.ok(encoded,'lazy module manifest must be available in the document');
const manifest=JSON.parse(encoded.replaceAll('&quot;','"').replaceAll('&lt;','<').replaceAll('&gt;','>').replaceAll('&amp;','&'));
for(const route of ['/assistant.js','/business-home.js','/order-rules.js']){
assert.ok(manifest.urls[route]);assert.equal(html.includes('<script src="'+manifest.urls[route]+'"'),false);
const asset=await get(manifest.urls[route]);assert.equal(asset.status,200);assert.match(asset.headers['cache-control'],/immutable/);assert.equal(new URL(manifest.urls[route],'http://local').searchParams.get('v'),asset.headers['x-asset-version']);
}
});
test('changing one dependency changes its URL and HTML ETag without invalidating other assets',async t=>{
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'asset-dependency-'));t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
const documentPath=path.join(dir,'index.html'),one=path.join(dir,'one.js'),two=path.join(dir,'two.css');fs.writeFileSync(documentPath,'<!doctype html><link href="/two.css" rel="stylesheet"><script src="/one.js" defer></script>');fs.writeFileSync(one,'old()');fs.writeFileSync(two,'body{}');