跪拜 Guibai
← Back to the summary

Don't Ship 25,000 Quiz Answers at Once: Split, Cache, and Prefetch

Frontend Mini-Game Has 25,000+ Answers: How to Avoid Loading All Data at Once?

When developing an online quiz mini-game, a common problem is that questions and answers keep growing, and the frontend needs a data-loading strategy. Suppose the game has 300+ questions, each with dozens or even hundreds of acceptable answers. If the user is only preparing to answer the first question but has to download the entire answer bank first, that is clearly not an ideal design. This article introduces three loading strategies and uses JavaScript to implement a simple on-demand loading solution.

Strategy 1: Package the Entire Answer Bank into the Frontend

The most direct method is to put all questions and answers into one JSON file:

const response = await fetch("/questions.json");
const questions = await response.json();

The advantage is simple implementation: after the download finishes, no more question data requests are needed. But as the data keeps growing, first-screen download, JSON parsing, and memory usage all increase. Note that the number of answers does not directly determine file size. What should actually be measured is the compressed transfer size, parsing time, and memory usage at runtime.

Strategy 2: Split by Category

If the question bank contains categories such as animals, geography, food, and music, the data can be split into multiple files. For example:

/public/questions/
  animals.json
  geography.json
  food.json
  music.json

When a user enters a category, only the corresponding file is loaded.

const cache = new Map();
async function loadCategory(category) {
  const allowed = new Set([ "animals", "geography", "food", "music" ]);
  if (!allowed.has(category)) {
    throw new Error("Unknown category");
  }
  if (cache.has(category)) {
    return cache.get(category);
  }
  const response = await fetch(
    `/questions/${category}.json`
  );
  if (!response.ok) {
    throw new Error("Failed to load questions");
  }
  const data = await response.json();
  cache.set(category, data);
  return data;
}

This approach has the advantage of reusing already downloaded data while avoiding requesting all categories at once. However, the cache consumes memory. Real projects should also consider cache size limits, version updates, and error retry.

Strategy 3: Separate Question List and Answer Index

For open-ended quiz games, another structure worth considering:

For example:

/questions/index.json
/answers/bird-001.json
/answers/fruit-002.json

This separates "what the next question is" from "what valid answers this question has". However, switching questions may generate more network requests. If each question only has 25 seconds, prefetching the next question's data should be considered, so that network waiting does not affect the timing experience.

A Real Design Scenario

For example, Krillion Infinite — Rarest Answer Practice is a free browser quiz practice game with 300+ questions and 25,000+ curated answers. It is not a traditional multiple-choice game; players need to type in as obscure but correct an answer as possible within 25 seconds. Scoring is determined by six rarity tiers, and it offers Classic and Endless modes. The site is an independently developed unofficial practice project and is not affiliated with the original Krillion. This scale of open-ended question bank is a suitable scenario for thinking about frontend data splitting, validation, and caching strategies. The code in this article is an independent design example and does not mean the site uses exactly the same data-loading architecture.

How Should You Choose?

If the compressed JSON is only a few tens of KB, one-time loading may already be good enough, and over-engineering is unnecessary. If the question bank grows to several MB and users only access a few categories each time, split loading is usually more worth considering. If answer validation needs to rely on the server, or the complete question bank should not be exposed on the client, server-side validation can be considered. The most important thing is not to decide on an architecture first, but to measure real file size, network latency, and first-screen performance.

Summary

For content-heavy browser mini-games, the following directions can be used:

  1. First measure the full question bank's size and parsing cost.
  2. Split category or question data according to actual usage scenarios.
  3. Cache already loaded data appropriately.
  4. Ensure the current question's validation data is ready before the timer starts.
  5. Prefetch subsequent questions moderately.

Frontend performance optimization does not necessarily require introducing complex state management or a database. In many cases, reasonable organization of static data can significantly improve the game experience.

Comments

Top 1 from juejin.cn, machine-translated. The original thread is authoritative.

组合搭配函数

Splitting by question is exactly the right approach — stuffing 25,000+ answers into the initial load is just making trouble for yourself. Putting answer validation on the server also gets to the root of it; the frontend only needs to handle display.