Home / PWA and Offline / Instant-loading Blog

Instant-loading Blog in JavaScript, Free with Live Demo

Free instant-loading blog in plain JavaScript. The Speculation Rules API prerenders posts while you hover, so they open almost instantly. Timing shows the difference.

Open live demoDownload HTML fileView code on GitHub
Instant-loading Blog JavaScript project: a blog where the next page is ready before you click

Runs on: Speculation Rules. Prerendering: Chrome and Edge 109+. Other browsers load pages normally.

What is the Instant-loading Blog?

Hover over a post title for a moment, then click. The page opens almost instantly because the browser already built it in the background. A timer at the top shows how fast the page appeared and whether it was prerendered.

This uses the Speculation Rules API, a small JSON block that tells the browser which links it may prerender and how eager to be. You can switch between eager, moderate and conservative to see the trade off.

Good for

  • Blogs and news sites
  • Product pages in shops
  • Improving Largest Contentful Paint
  • Multi page sites that want app like speed

What this project does

How it works

  1. Declare the rulesA JSON script tag says which links may be prerendered and how eager the browser should be.
  2. Prerender on hoverWith moderate eagerness, holding the pointer on a link for about 200 ms starts building that page in a hidden tab.
  3. Swap on clickClicking activates the finished page. activationStart shows it was prerendered and how much time was saved.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

<script type="speculationrules">
{
  "prerender": [{
    "where": { "href_matches": "/*\\?post=*" },
    "eagerness": "moderate"
  }]
}
</script>
<script>
  const nav = performance.getEntriesByType("navigation")[0];
  const wasPrerendered = nav.activationStart > 0;
</script>

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

What are speculation rules?

A script tag of type speculationrules with JSON inside. It lists URLs the browser may prefetch or prerender before the user clicks.

Does prerendering waste data?

It can, which is why moderate eagerness waits for a short hover. Only pages people are likely to open get prerendered.

Which browsers support it?

Chrome and Edge. Other browsers ignore the rules and load pages normally, so nothing breaks.

More PWA and Offline projects