Using simple numeric mapping for books (b: 1 for Genesis) and testament flags, I reduced the total dataset size down to a fraction of its original weight.
Lazy Loading & Client-Side Randomization
Loading 4.5MB on the client upfront would tank the site's performance metrics. To solve this, I split the dataset into smaller, logical chunks (by Book and Testament).
For the "Random Generator" feature, instead of a slow SQL ORDER BY RANDOM() LIMIT 1 database call, ScriptureGen uses a highly optimized serverless function at the edge. The edge function keeps a lightweight index of verse coordinates, picks a random seed, and fetches only the specific tiny JSON chunk containing the selected verse.
For the full-text search, I implemented an asynchronous lazy-loaded client-side search index. The search module is only downloaded when the user focuses on the search bar. We then run an in-memory search using a lightweight indexing library, yielding search results under 10 milliseconds.
Technical Takeaways
- Zero DB Cost: The site runs completely serverless on the edge, costing $0/month to host.
- Instant Performance: Page load times are under 100ms, and verse generation is instantaneous.
- Privacy First: Because all processing happens on the edge and client, there is no tracker, database logging, or account creation needed.
If you want to check out the speed or test the search queries yourself, take a look at ScriptureGen. I would love to hear your thoughts on how you would optimize a static relational dataset like this!
Top comments (0)