
sql.js + IndexedDB: Building an Offline-First Web App
Originally published at recca0120.github.io sql.js lets you run SQLite inside the browser with an API that feels nearly identical to the server-side version. But there is a catch I only discovered the first time I used it: close the tab and all your data is gone. The reason is straightforward—sql.js keeps the entire database in memory with no automatic persistence. If you want to build an application that truly works offline and survives a browser restart, you have to handle the storage layer yourself. Why IndexedDB The first instinct is usually localStorage because the API is dead simple. But it has two hard limitations that rule it out: The storage cap is around 5 MB , and exceeding it throws an exception. A SQLite file with any real data can blow past that easily. It can only store strings . sql.js exports a Uint8Array , so you would have to Base64-encode it before writing and decode it back on read. That is extra complexity, and the encoding alone inflates the binary size by roughl
Continue reading on Dev.to
Opens in a new tab




