Showing page one before the file has arrived

Click a link to a long PDF and you wait, watching nothing happen. The reason is the shape of an ordinary PDF file: the list saying where everything in it is sits at the very end, so a reader has to receive the whole document before it can put a single page on screen. Two hundred pages, and you wait for two hundred pages to read the first one.

Written the other way round, the file opens with page one, everything page one needs, and a small list saying where each of the other pages begins. The first page appears while the rest is still coming down the wire, and jumping to page fifty fetches page fifty alone. The document is exactly the same one: anybody who opens it on their own machine sees no difference at all. The example below measures it — the ordinary file makes you wait for all of it, the reordered one for a quarter.

What this example shows

  • The same document written twice, and what each one makes you wait for.
  • A reader on a slow line showing page one before the rest arrives.
  • Going straight to one page fetching that page, not the document.

The code that writes it, in full

Whole programs, hundreds of lines long, for whoever writes your software.

Read the Rust source Read the Python source

The document itself

Open the document in English Open the document in French

First page of Showing page one before the file has arrived

What this document weighs

This document weighs 41,231 bytes.

See every document measured.

Examples near this one

A minimal PDF

The smallest complete file: a page, and shapes drawn on it.

Making the file smaller

The same document written twice, plainly and packed, with what each one weighs and what the packing saved.

A document locked with a password

A page anybody can open and print, and nobody can copy or alter. Every word of it is scrambled inside the file, and the page states the password that lifts what is withheld.

Fonts kept inside the file

Text set in a typeface the file carries inside it, cut down to the letters actually used, and still searchable, copyable and readable aloud.

Letters you draw yourself

A tick, a cross and a dash drawn by the program, added to the document as a font, and set among ordinary words.

A page that carries no font

Four faces every reader already draws, set on one page, so the file holds no font at all — and the example weighs the same lines both ways to say what that saves.

Every example, by subject