Need help with readium-js-viewer?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

451 Stars 179 Forks BSD 3-Clause "New" or "Revised" License 1.8K Commits 207 Opened issues


👁 ReadiumJS viewer: default web app for Readium.js library

Services available


Need anything else?

Contributors list

Note: Please don't use the zip download feature on this repo as this repo uses submodules and this is not supported at present by github and will result in an incomplete copy of the repo.


EPUB reader written in HTML, CSS and Javascript.

This Readium software component implements the Readium Chrome extension / app for offline reading ( ), and the "cloud reader" for online e-books ( is the deployment URL for automated builds from the develop branch, links to the latest app release from the master branch).

Please see for more information about the underlying rendering engine.


BSD-3-Clause ( )

See license.txt.


  • A decent terminal. On Windows, GitBash works great ( or or ), and optionally Cygwin adds useful commands ( ).
  • NodeJS ( ) v4+ (Note that NodeJS v6+ and NPM v3+ are now supported, including NodeJS v7+ and NPM v4+)
    • Optionally: Yarn ( ) v0.23+


Git initialisation

  • git clone --recursive -b BRANCH_NAME readium-js-viewer
    (replace "BRANCH_NAME" with e.g. "develop")
  • cd readium-js-viewer
  • git submodule update --init --recursive
    to ensure that the readium-js-viewer chain of dependencies is initialised (readium-js, readium-shared-js)
  • git checkout BRANCH_NAME && git submodule foreach --recursive "git checkout BRANCH_NAME"
    (or simply
    inside each repository / submodule, and manually enter the desired branch name:
    git checkout BRANCH_NAME
    ) Git should automatically track the corresponding branch in the 'origin' remote.

Advanced usage (e.g. TravisCI) - the commands below automate the remote/origin tracking process (this requires a Bash-like shell):

  • for remote in `git branch -r | grep -v \> | grep -v master`; do git branch --track ${remote#origin/} $remote; done
    to ensure that all Git 'origin' remotes are tracked by local branches.
  • git checkout `git for-each-ref --format="%(refname:short) %(objectname)" 'refs/heads/' | grep $(git rev-parse HEAD) | cut -d " " -f 1`
    to ensure that Git checks-out actual branch names (as by default Git initializes submodules to match their registered Git SHA1 commit, but in detached HEAD state)

(repeat for each repository / submodule)

Source tree preparation

  • npm run prepare:all
    (to perform required preliminary tasks, like patching code before building)
    • OR:
      yarn run prepare:yarn:all
      (to use Yarn instead of NPM for node_module management)

Note that in some cases, administrator rights may be needed in order to install dependencies, because of NPM-related file access permissions (the console log would clearly show the error). Should this be the case, running

sudo npm run prepare:all
usually solves this.

Note that the above command executes the following:

  • npm install
    (to download dependencies defined in
    ... note that the
    option can be used to avoid downloading development dependencies, for example when testing only the pre-built
    folder contents)
  • npm update
    (to make sure that the dependency tree is up to date)
  • + some additional HTTP requests to the GitHub API in order to check for upstream library updates (wherever Readium uses a forked codebase)

Typical workflow

No RequireJS optimization:

  • npm run http
    (to launch an http server. This automatically opens a web browser instance to the HTML files in the
    folder, choose
    , or the
    variant which do include only the reader view, not the ebook library view)
  • Hack away! (e.g. source code in the
  • Press F5 (refresh / reload) in the web browser

Or to use optimized Javascript bundles (single or multiple):

  • npm run build
    (to update the RequireJS bundles in the build output folder)
  • npm run http:watch
    (to launch an http server. This automatically opens a web browser instance to the HTML files in the
    folder, choose
    , or the
    variants which do include only the reader view, not the ebook library view)
  • npm run http
    (same as above, but without watching for file changes (no automatic rebuild))

And finally to update the distribution packages (automatically calls the

task above, so
npm run build
is redundant):
  • npm run dist
    (Chrome extension and cloud reader, including the lite / no-library variant)

The above task takes a lot of time (as it builds distributable packages for all ReadiumJS flavours), and is in fact not strictly necessary to test the cloud reader (see

npm run http
above, using the "no optimise" RequireJS option). Thankfully, the packaged code for the Chrome App / Extension can be quickly generated using this build command instead:
  • npm run chromeApp
    (generates a ready-to-use Readium packaged app for Chrome, inside the usual

Remember to activate "developer mode" in the Chrome web browser, so that the Readium packaged app / extension can be added directly from the

folder. Subsequently (after each build), the app can simply be reloaded.

Also note that the built-in local HTTP server functionality (

npm run http
) is primarily designed to serve the Readium application at development time in its "exploded" form (
, etc. folders). It is also possible to use any arbitrary HTTP server as long as the root folder is
(so that the application assets ; CSS, images, fonts ; can be loaded relative to this base URL). Example with the built-in NodeJS server:
node node_modules/http-server/bin/http-server -a -p 8080 -c-1 .
. Also note that the
IP address which is used by default when invoking the
npm run http
command can be set to
in order to automatically bind the HTTP server to the local LAN IP, making it possible to open the Readium app in a web browser from another machine on the network. Simply set the
environment variable to
(e.g. using
export RJS_HTTP_IP=""
from the command line), or for a less permanent setting:
RJS_HTTP_IP="" npm run http
(the environment variable only "lasts" for the lifespan of the NPM command).

Remark: a log of HTTP requests is preserved in

. This file contains ANSI color escape codes, so although it can be read using a regular text editor, it can be rendered in its original format using the shell command:
cat http_app.log
(on OSX / Linux), or
sed "s,x,x,g" http_app-ebooks.log
(on Windows).

HTTP CORS (separate domains / origins, app vs. ebooks)

By default, a single HTTP server is launched when using the

npm run http
task, or its "watch" and "nowatch" variants (usage described in the above "Typical workflow" section). To launch separate local HTTP servers on two different domains (in order to test HTTP CORS cross-origin app vs. ebooks deployment architecture), simply invoke the equivalent tasks named with
instead of
. For example:
npm run http2
. More information about real-world HTTP CORS is given in the "Cloud reader deployment" section below.

Remark: logs of HTTP requests are preserved in two separate files

. They contains ANSI color escape codes, so although they can be read using a regular text editor, they can be rendered in their original format using the shell command:
cat http_app.log
(on OSX / Linux), or
sed "s,x,x,g" http_app.log
(on Windows).


Assuming a fork of
is made under
, the
file ( ) will still point to the original submodule URL (at
, instead of
). Thankfully, one can simply modify the
file by replacing
, and do this for every submodule (
). Then the Git command
git submodule sync
can be invoked, for each submodule.

Plugins integration

When invoking the

npm run build
command, the generated
folder contains RequireJS module bundles that include the default plugins specified in
(see the plugins documentation ). Developers can override the default plugins configuration by using an additional file called
. This file is git-ignored (not persistent in the Git repository), which means that Readium's default plugins configuration is never at risk of being mistakenly overridden by developers, whilst giving developers the possibility of creating custom builds on their local machines.

For example, the

plugin can be activated by adding it to the
section in
. Then, in order to create / remove highlighted selections, simply comment
in the
file (this will enable an additional toolbar button).

RequireJS bundle optimisation

Note that by default, compiled RequireJS bundles are minified / mangled / uglify-ed. You can force the build process to generate non-compressed Javascript bundles by setting the

environment variable to "no" or "false" (any other value means "yes" / "true").

This may come-in handy when testing / debugging the Chrome Extension (Packaged App) in "developer mode" directly from the

folder (i.e. without the sourcemaps manually copied into the script folder).


Mocha-driven UI tests via Selenium (not PhantomJS, but actual installed browsers accessed via WebDriver):

  • npm run test:firefox
  • npm run test:chrome
  • npm run test:chromeApp

npm run test
(runs all of the above)

PS: you may need to install the Chrome WebDriver from

Via SauceLabs:

  • npm run test:sauce:firefox
  • npm run test:sauce:chrome
  • npm run test:sauce:chromeApp

npm run test:sauce
(runs all of the above)

Travis (Continuous Integration) automatically uses a chromeApp and Firefox test matrix (2x modes), and uses SauceLabs to actually run the test. See


See the

folder contents (generated by
npm run dist
  • cloud-reader
  • cloud-reader-lite
    (same as above, without the ebook library feature)
  • chrome-app
    (Google Chrome Extension / Packaged App)

The source maps are generated separately, so they are effectively an opt-in feature (simply copy/paste them next to their original Javascript file counterparts, e.g. in the

folder). The command
npm run dist+sourcemap
can be used to ensure that sourcemap files are copied across into their respective dist folders (note that this command invokes
npm run dist

Note that

npm run http
folder is not the only way to test Readium "locally". The distributable / packaged Readium app in the
folder can also execute in any arbitrary local HTTP server, such as the built-in NodeJS option
node node_modules/http-server/bin/http-server -a -p 8080 -c-1 ..
(assuming the current command line folder is
). Then, simply open the URL
(or the legacy
file format), which explicitely specifies the location of the ebook library (alternatively, you may copy/paste the
folder manually under
, and open
without parameters).

Cloud reader deployment

The contents of the

distribution folder (see section above) can be uploaded to an HTTP server as-is (either in the root, or any subfolder path, and a child (of the parent cloud-reader folder)
folder is expected to contain exploded or zipped EPUBs (e.g. or for extracted files), and the
file is expected to describe the available ebooks in the online library (see the existing examples in
repository). Note that
is the legacy format, now superseded by OPDS XML (a specialized Atom feed format). Readium supports both formats, but OPDS is recommended. The
URL query parameter can be used to specify a different location for the OPDS/JSON file that describes the ebook library contents, for example:
(assuming both HTTP servers are suitably configured with CORS), or for example
(assuming a folder named
exists as a sibling of
, and this folder contains the
file). Finally, the ebook library can be permanently set to a specific location, by editing
and by replacing the value of
config : {
        'readium_js_viewer/ModuleConfig' : {
            'epubLibraryPath': VALUE

:point_right: Note: It is STRONGLY RECOMMENDED that when deploying the CloudReader that you do not try to load packed (i.e. still zipped) EPUBs. This is because there are (so far) insurmountable reasons why the loading of large resources (e.g. videos, etc.) will be so slow as to be unacceptable or even time out. Instead, deployers should:

  • Unpack / unzip EPUBs in remote storage, instead of serving the actual EPUB files, which will allow the assets to be streamed in the normal fashion
  • De-obfuscate fonts on the server

For more info, see the document here

The issues associated with transmitting unencrypted fonts can be mitigated using HTTPS, HTTP_REFERER, and other web techniques designed to protect content ( e.g. )


distribution does not feature an ebook library, so EPUBs must be specified via the URL parameter (HTTP GET), for example:
(assuming both HTTP servers are suitably configured with CORS), or for example
(assuming a folder named
exists as a sibling of
, and this folder contains the
file (note that the folder name is arbitrary, and it may in fact follow the default naming convention:

Example of Readium app hosted at Surge, and EPUBs hosted at Firebase: (note that only the host specifies HTTP CORS headers, the server does not configure anything special to achieve this unilateral cross-origin resource sharing)

For more information about HTTP CORS, see

NPM (Node Package Manager)


All packages "owned" and maintained by the Readium Foundation are listed here:

Note that although Node and NPM natively use the CommonJS format, Readium modules are currently only defined as AMD (RequireJS). This explains why Browserify ( ) is not used by this Readium project. More information at and

  • Make sure
    npm install readium-js-viewer
    completes successfully ( )
  • Execute
    npm run http
    , which opens a web browser to a basic RequireJS bootstrapper located in the
    folder (this is not a production-ready minified application)

Note: the

option after
npm install readium-js-viewer
can be used to force the download of development dependencies, but this is kind of pointless as the code source and RequireJS build configuration files are missing. See below if you need to hack the code.

How to use (RequireJS bundles / AMD modules)


directory contains two distinct folders:

Single bundle


folder contains
(and its associated source-map file, as well as a RequireJS bundle index file (which isn't actually needed at runtime, so here just as a reference)), which aggregates all the required code (external library dependencies included, such as Underscore, jQuery, etc.), as well as the "Almond" lightweight AMD loader ( ).

This means that the full RequireJS library ( ) is not actually needed to bootstrap the AMD modules at runtime, as demonstrated by the HTML file in the

folder (trimmed for brevity):

Multiple bundles


folder contains several Javascript bundles (and their respective source-map files, as well as RequireJS bundle index files):
  • readium-external-libs.js
    : aggregated library dependencies (e.g. Underscore, jQuery, etc.)
  • readium-shared-js.js
    : shared Readium code (basically, equivalent to the
    folder of the "readium-shared-js" submodule)
  • readium-js.js
    : the core Readium code (basically, equivalent to the
    folder of the "readium-js" submodule)
  • readium-js-viewer.js
    : this Readium code (mainly, the contents of the
  • readium-plugin-example.js
    : simple plugin demo
  • readium-plugin-annotations.js
    : the annotation plugin (DOM selection + highlight), which bundle actually contains the "Backbone" library, as this dependency is not already included in the "external libs" bundle. )

In addition, the folder contains the full

library ( ), as the above bundles do no include the lightweight "Almond" AMD loader ( ).

Usage is demonstrated by the HTML file in the

folder (trimmed for brevity):

Note how the "external libs" set of AMD modules can be explicitly described using the

RequireJS configuration directive (this eliminates the apparent opacity of such as large container of library dependencies):

CSON vs. JSON (package.json)

CSON = CoffeeScript-Object-Notation ( )

Running the command

npm run cson2json
will re-generate the
JSON file. For more information, see comments in the master
CSON file.

Why CSON? Because it is a lot more readable than JSON, and therefore easier to maintain. The syntax is not only less verbose (separators, etc.), more importantly it allows comments and line breaking!

Although these benefits are not so critical for basic "package" definitions, here

declares relatively intricate
tasks that are used in the development workflow.
offers a lightweight technique to handle most build tasks, as NPM CLI utilities are available to perform cross-platform operations (agnostic to the actual command line interface / shell). For more complex build processes, Grunt / Gulp can be used, but these build systems do not necessarily offer the most readable / maintainable options.

Downside: DO NOT invoke

npm init
npm install --save
, as this would overwrite / update the JSON, not the master CSON!

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.