HTML5 game publishing

A Recently Played Games List With localStorage, and the Consent Question

Remember the last games a visitor opened with a few lines of code, handle blocked storage, validate against the feed and decide how it fits your cookie notice.

PlayKovo Team4 min read
Games currently available on PlayKovo. Open a title to see its current listing.

A "continue playing" row at the top of a games page is one of the most effective small features a games section can have. Visitors who come back see the games they played last, and tapping one is easier than finding it again. You do not need accounts or a database. The browser's own storage is enough. This post shows how to build a recently-played list with localStorage, and covers the points people skip: privacy, consent, limits and what happens when storage is blocked.

What you are building

When a visitor opens a game page, you save that game's slug, title and thumbnail with a timestamp. On your games list page and your home page you read the list and show the last four to eight games. Everything lives in the visitor's own browser. You never see it, you do not need a server, and clearing site data removes it.

The code

const KEY = 'recent-games-v1';
const MAX = 8;

function readRecent() {
  try {
    const list = JSON.parse(localStorage.getItem(KEY));
    return Array.isArray(list) ? list : [];
  } catch { return []; }
}

function rememberGame(game) {
  try {
    const list = readRecent().filter(g => g.slug !== game.slug);
    list.unshift({
      slug: game.slug,
      title: game.title,
      thumb: game.thumbnail,
      at: Date.now(),
    });
    localStorage.setItem(KEY, JSON.stringify(list.slice(0, MAX)));
  } catch { /* storage blocked or full: do nothing */ }
}

Notes on the choices:

  • Wrap every access in try/catch. Storage can be unavailable in private windows, with blocked cookies and in some embedded contexts, and it can throw when full. The feature should disappear quietly, not break the page.
  • Version the key (-v1). If you change the data shape later you can start fresh instead of crashing on old data.
  • Remove then insert at the front, so replaying a game moves it to the top and the list has no duplicates.
  • Store the smallest useful record. A slug is enough to rebuild the card from the feed. Storing title and thumbnail lets you render instantly, but they can go stale, so refresh them from the feed when you can.

Show it, and keep it honest

Render the list with the same card component you use elsewhere. Do it on the client after load, so the page's static HTML stays cacheable (see static pages and caching for a games section). Hide the section when the list is empty rather than showing a blank heading. A "Clear" link that wipes the list gives visitors control and is a good sign of respect.

Check each remembered game against the current feed before you show it. Games leave the catalog, and a card that leads to a dead page is the opposite of helpful. See what visitors see when a game goes away and caching the feed and removing dead games.

This is the part to think about before shipping. Writing to localStorage stores information on the visitor's device. In some jurisdictions, including those covered by the EU's ePrivacy rules, storing or reading information on a device generally needs consent unless it is strictly necessary to provide a service the user asked for. Whether a "recently played" convenience counts as strictly necessary is a legal question that depends on where you operate and how the rules are applied. This post is not legal advice. Two safe options:

  1. Treat it as optional storage. Only write after the visitor accepts your cookie notice. That aligns with cookie notices and privacy policies for a site with embedded games.
  2. Ask for it. Show a small "Remember what I played" toggle that the visitor turns on.

Whatever you choose, say it in your privacy policy. List the key name, what it stores, that it stays on the device and how to clear it. Never store personal data, and do not combine the list with an identifier you send to analytics.

Remember that launches in the PlayKovo partner dashboard are counted only after cookie acceptance, so a visitor who declines will not appear there. See why the dashboard shows fewer launches than your real traffic.

Limits to plan for

  • Per device, per browser. A visitor's list on their phone is not on their laptop. Do not promise otherwise.
  • Per origin. If your site runs on several subdomains, each has its own storage.
  • Quota. Browsers allow a few megabytes per origin, and eight small objects are nowhere near it. Do not store thumbnails as data URLs.
  • Cleared data. Some browsers clear storage for sites a visitor has not used in a while. Treat the list as a convenience, not a record.

Variations worth building

  • A "Play again" button on the last game, in your header.
  • "Because you played X" suggestions, using tags from the feed, computed on the client without sending anything away.
  • A favourites list the visitor controls with a heart button, stored the same way.

Each is a small amount of code, and each gives returning visitors a reason to come back. To see whether it works, compare return visits before and after, using your own analytics. See measuring your games section.

We use optional cookies for site analytics and site advertising. You can change your choice later. Privacy policy.