Skip to content

Commit 9a73858

Browse files
Ajit Pratap Singhclaude
authored andcommitted
perf(website): add WASM preload hint and versioned SW cache key (issues #402, #403)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ff32753 commit 9a73858

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

website/next.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ const withAnalyzer = withBundleAnalyzer({
88
const nextConfig: NextConfig = {
99
async headers() {
1010
return [
11+
{
12+
source: '/wasm/:path*',
13+
headers: [
14+
{
15+
key: 'Cache-Control',
16+
value: 'public, max-age=31536000, immutable',
17+
},
18+
],
19+
},
1120
{
1221
source: '/(.*)',
1322
headers: [

website/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"dev": "next dev",
77
"prebuild": "node scripts/split-changelog.js",
88
"build": "next build",
9+
"postbuild": "npm run update-sw-hash",
910
"start": "next start",
10-
"analyze": "ANALYZE=true next build"
11+
"analyze": "ANALYZE=true next build",
12+
"update-sw-hash": "node -e \"const {createHash} = require('crypto'); const fs = require('fs'); const hash = createHash('sha256').update(fs.readFileSync('public/wasm/gosqlx.wasm')).digest('hex').slice(0,8); const sw = fs.readFileSync('public/wasm-sw.js','utf8').replace(/gosqlx-wasm-[a-f0-9-]+/, 'gosqlx-wasm-' + hash); fs.writeFileSync('public/wasm-sw.js', sw); console.log('SW cache key updated to: gosqlx-wasm-' + hash);\""
1113
},
1214
"dependencies": {
1315
"@codemirror/lang-sql": "^6.10.0",

website/public/wasm-sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const WASM_CACHE = 'gosqlx-wasm-v1';
1+
const WASM_CACHE = 'gosqlx-wasm-7fe84bbe';
22
const WASM_URL = '/wasm/gosqlx.wasm';
33

44
self.addEventListener('install', (event) => {

website/src/app/playground/page.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ export const metadata: Metadata = {
88

99
export default function PlaygroundPage() {
1010
return (
11-
<div className="h-[calc(100vh-64px)]">
12-
<PlaygroundLoader />
13-
</div>
11+
<>
12+
{/* Preload WASM binary to start download before JS hydration */}
13+
<link
14+
rel="preload"
15+
href="/wasm/gosqlx.wasm"
16+
as="fetch"
17+
crossOrigin="anonymous"
18+
/>
19+
<div className="h-[calc(100vh-64px)]">
20+
<PlaygroundLoader />
21+
</div>
22+
</>
1423
);
1524
}

0 commit comments

Comments
 (0)