Skip to content

Commit 64c0d0f

Browse files
nishadclaude
andcommitted
fix: use chunked mode with suffixed file for GitHub Pages
GitHub Pages doesn't return Content-Length properly when gzip Vary header is present. Work around by: 1. Using chunked serverMode with entire file as single chunk 2. Renaming database file with "0" suffix (e.g., .sqlite30) 3. Using suffixLength: 1 so library correctly builds URL 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 9be462b commit 64c0d0f

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed
File renamed without changes.

src/App.svelte

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
const DEFAULT_SQL_QUERY = `SELECT * FROM titles WHERE title_id LIKE "tt00000%";`;
102102
103103
/**
104-
* Default database URL (relative to current origin).
104+
* Default database URL prefix for chunked mode.
105+
* The actual file is at this URL + "0" (e.g., ...sqlite30)
105106
* @constant {string}
106107
*/
107108
const DEFAULT_DB_URL = "https://nishad.github.io/sql.js-httpvfs-playground/db/imdb-titles-100000_1024_indexed.sqlite3";
@@ -215,23 +216,28 @@
215216
async function queryDb() {
216217
const fileSizeNum = Number(dbFileSize);
217218
218-
// Build config based on whether file size is provided
219-
// When file size is specified, use "chunked" mode which allows setting databaseLengthBytes
220-
// This is required for servers like GitHub Pages that don't return Content-Length properly
221-
const config = fileSizeNum > 0
222-
? {
223-
serverMode: "chunked",
224-
urlPrefix: dbUrl,
225-
requestChunkSize: Number(pageSize),
226-
databaseLengthBytes: fileSizeNum,
227-
serverChunkSize: fileSizeNum, // Single chunk = entire file
228-
suffixLength: 0,
229-
}
230-
: {
231-
serverMode: "full",
232-
url: dbUrl,
233-
requestChunkSize: Number(pageSize),
234-
};
219+
let config;
220+
221+
if (fileSizeNum > 0) {
222+
// When file size is known, use chunked mode with the entire file as a single chunk
223+
// This bypasses the Content-Length detection issues with GitHub Pages
224+
// The file should exist at urlPrefix + "0" (e.g., database.sqlite30)
225+
config = {
226+
serverMode: "chunked",
227+
urlPrefix: dbUrl,
228+
requestChunkSize: Number(pageSize),
229+
databaseLengthBytes: fileSizeNum,
230+
serverChunkSize: fileSizeNum,
231+
suffixLength: 1,
232+
};
233+
} else {
234+
// Fallback to full mode when file size is not provided
235+
config = {
236+
serverMode: "full",
237+
url: dbUrl,
238+
requestChunkSize: Number(pageSize),
239+
};
240+
}
235241
236242
const worker = await createDbWorker(
237243
[

0 commit comments

Comments
 (0)