ZIM Redirect Vs Alias

From openZIM
Jump to navigation Jump to search

When one need to have two ZIM paths pointing to the same data, there is since ZIM format 6.2 (libzim 9.1) two possibilities: either create a redirect entry or an alias entry.

What is the difference, and when should we prefer one over the other?

TL;DR

To oversimplify, when you need two ZIM paths to point to the same data, use redirects for anything which contains relative paths (HTML, CSS, JS) and alias for everything else (images, videos, ...).

ZIM Alias

ZIM alias are more recent than redirects and also lighter, but they obviously have downside.

In term of implementation, an alias is simply another ZIM entry pointing to the same data (stored in clusters) than another ZIM entry (already added to the ZIM at creation time).

When reading, the libzim has very limited capability to detect an entry in an alias, because we just have two ZIM entries pointing to the same data.

It is hence perfect for "data" like images, videos, ... but is in general not adequate for anything "HTML-oriented" which contains relative paths (HTML, CSS and JS typically).

The limitation of alias

Let's use an example.

We have an HTML document at path1/index.html, which contains a tag pointing to an image stored ad `images/picture.png. The HTML code is hence something like <img src="../images/picture.png">.

Let's say we want that visitors of path2/path2.1/index.html to see the same page than when visiting path1/index.html.

If we use an alias, then path2/path2.1/index.html HTML document will still use same <img src="../images/picture.png">

ZIM redirects

This is where we need a redirect. A redirect is a special ZIM entry which stores information about the fact that redirect entry points to target entry. At read time, it is hence possible to really redirect the (Kiwix) reader to the target path/URL.

For instance in our example and with kiwix-serve reader, the reader will issue a real HTTP 302 redirect when user open path2/path2.1/index.html, so that his browser really moves to path1/index.html ; from here HTML document will be interpreted and no relative paths will be broken.