JACOB PARK
SOFTWARE / WEB

A live feed should not need a loading screen

Build a resilient content feed with useful HTML first, safe browser updates, and a fallback that preserves real links when an API fails.

Make the page useful before JavaScript

A writing section has a straightforward job: show people something worth reading and give them a link. If the entire section starts as a loading message, that job depends on a script running, an API responding, and the response being usable.

A live feed can keep content fresh without making it the only source of content. Put a verified selection of article links in the initial HTML, then let JavaScript refresh that selection. The page has something useful to offer at every stage.

This portfolio uses that pattern for its Medium articles. The selected links are present in the document. A browser request refreshes them from an owner-verified, curated endpoint. If the request fails, the links already on the page stay available.

<section aria-labelledby="writing-title">
  <h2 id="writing-title">Selected writing</h2>
  <div data-feed>
    <a href="https://medium.com/@example/an-article">
      A verified article title
    </a>
  </div>
</section>

The example address is a placeholder. In a published page, the title and URL should come from an article that actually exists and belongs in the selection. A decorative card with a click handler is a weaker starting point than an ordinary link with an href.

There is a search benefit to making content available early, too. Google processes JavaScript, but fetching a document and rendering it are separate stages. Its JavaScript SEO guidance recommends server-side or pre-rendered content for users and crawlers. Static HTML is enough for this small site; a framework is not required to make the links available.

Validate before replacing anything

The browser should not replace a useful selection simply because a request completed. Check the HTTP response, the expected data shape, and the destinations of the links. A successful HTTP status is only one part of that check.

For this site's feed, the response must identify the expected owner and the professional curation. The browser also accepts only HTTPS links on Medium. The short example below shows the replacement rule; the endpoint itself should enforce its own source and curation rules.

const feed = document.querySelector('[data-feed]');

async function refreshFeed() {
  const controller = new AbortController();
  const timer = setTimeout(() => controller.abort(), 5500);

  try {
    const response = await fetch('/api/medium', {
      signal: controller.signal
    });
    if (!response.ok) return;

    const data = await response.json();
    if (data.owner !== 'jacobpark0131' ||
        data.curation !== 'professional' ||
        !Array.isArray(data.posts)) return;

    const cards = data.posts.slice(0, 3).flatMap(post => {
      try {
        const url = new URL(post.link);
        if (url.protocol !== 'https:' ||
            url.hostname !== 'medium.com' ||
            typeof post.title !== 'string') return [];
        const link = document.createElement('a');
        link.href = url.href;
        link.textContent = post.title;
        return [link];
      } catch { return []; }
    });

    if (cards.length) feed.replaceChildren(...cards);
  } catch {
    // The verified HTML links remain available.
  } finally {
    clearTimeout(timer);
  }
}

refreshFeed();

Notice the order: assemble a usable replacement, then update the document. The code never empties the container at the beginning of the request. An error response, invalid JSON, or an empty validated selection leaves the existing links in place.

Using textContent for a title also keeps feed text as text. It does not interpret a title as HTML. The timeout bounds the wait for this refresh; it does not turn a failed request into a successful one.

Keep the layout steady

A fallback should look like part of the page. Use the same card structure, title treatment, and excerpt length in the initial HTML and the live renderer. If those versions differ dramatically, the refresh can move content around while someone is trying to read it.

A stored selection can make later visits feel quicker, but it needs an expiry and the same validation as a fresh response. It should support the HTML fallback rather than become another dependency required to see anything.

Content freshness has a separate authoring step. In this repository, a refresh helper updates the static selection before publishing when the curated articles change. The browser can fetch newer entries between releases, while the next release brings the initial HTML back into alignment.

Test the unhappy path on purpose

Check the page with JavaScript disabled. Then block the feed request, return an error, and try an empty response. The section should retain working links. Test keyboard navigation as well: readers should be able to reach a card and follow it without a pointer.

These checks answer a more useful question than whether the loading animation looks polished. They show whether the page still does its job when one of its dependencies is missing.

The same habit applies outside web interfaces. In a failed-logon investigation, an empty query result also needs context before it becomes a conclusion. To see the rest of the site’s technical interests, visit the toolkit notebook.

References

BACK TO THE NOTEBOOK
IN THIS NOTE
  1. Make the page useful before JavaScript
  2. Start with real links
  3. Validate before replacing anything
  4. Keep the layout steady
  5. Test the unhappy path on purpose
  6. References