forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(insights): Use insights to prefetch bundles in priority order
Use the insights data to pre-fetch bundles in priority order based on usage statistics.
- Loading branch information
Showing
27 changed files
with
358 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/qwik-city/buildtime/runtime-generation/generate-service-worker.unit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { suite } from 'uvu'; | ||
import { equal } from 'uvu/assert'; | ||
import type { BuildContext, BuildRoute } from '../types'; | ||
import type { QwikManifest, InsightManifest } from '@builder.io/qwik/optimizer'; | ||
import type { AppBundle } from '../../runtime/src/service-worker/types'; | ||
import { generateLinkBundles } from './generate-service-worker'; | ||
|
||
const swSuite = suite('lint'); | ||
|
||
swSuite('incorporate qwik-insights', () => { | ||
const routes: BuildRoute[] = [ | ||
{ | ||
routeName: '/', | ||
pattern: /\//, | ||
filePath: './src/routes/index.tsx', | ||
layouts: [], | ||
} /* satisfies Partial<BuildRoute> */ as any, | ||
{ | ||
routeName: '/routeA', | ||
pattern: /\/routeA/, | ||
filePath: './src/routes/routeA/index.tsx', | ||
layouts: [], | ||
} /* satisfies Partial<BuildRoute> */ as any, | ||
]; | ||
const ctx: BuildContext = { routes } /* satisfies Partial<BuildContext> */ as any; | ||
const appBundles: AppBundle[] = [ | ||
['q-bundle-a.js', [12]], | ||
['q-bundle-b.js', [34]], | ||
['q-bundle-123.js', [123]], | ||
['q-bundle-234.js', [234]], | ||
['q-bundle-345.js', [345]], | ||
]; | ||
const manifest: QwikManifest = { | ||
bundles: { | ||
'q-bundle-a.js': { | ||
origins: ['./src/routes/index.tsx'], | ||
} /* satisfies Partial<QwikManifest['bundles'][0]> */ as any, | ||
'q-bundle-b.js': { | ||
origins: ['./src/routes/routeA/index.tsx'], | ||
} /* satisfies Partial<QwikManifest['bundles'][0]> */ as any, | ||
'q-bundle-123.js': { | ||
symbols: ['s_123'], | ||
} /* satisfies Partial<QwikManifest['bundles'][0]> */ as any, | ||
'q-bundle-234.js': { | ||
symbols: ['s_234'], | ||
} /* satisfies Partial<QwikManifest['bundles'][0]> */ as any, | ||
'q-bundle-345.js': { | ||
symbols: ['s_345'], | ||
} /* satisfies Partial<QwikManifest['bundles'][0]> */ as any, | ||
}, | ||
} /* satisfies Partial<QwikManifest> */ as any; | ||
const prefetch: InsightManifest['prefetch'] = [ | ||
{ route: '/', symbols: ['123', '234'] }, | ||
{ route: '/routeA', symbols: ['345'] }, | ||
]; | ||
const [_, routeToBundles] = generateLinkBundles(ctx, appBundles, manifest, prefetch); | ||
equal(routeToBundles['/'], ['q-bundle-123.js', 'q-bundle-234.js', 'q-bundle-a.js']); | ||
equal(routeToBundles['/routeA'], ['q-bundle-345.js', 'q-bundle-b.js']); | ||
}); | ||
|
||
swSuite.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.