Self-Hosting Assets for the Document Authoring Library

By default, the Document Authoring library will fetch the required files (fonts, emoji data, etc.) from our public content delivery network (CDN), and no further configuration is needed. This guide covers the steps required to self-host the assets. Self-hosting allows you to maintain full control over the assets, optimize performance, and ensure availability, even in offline environments.

Prerequisites

Ensure you’ve followed the relevant getting started guide and that you have the @pspdfkit/document-authoring package installed. This package contains the necessary files to set up the library. For self-hosting, you’ll need to supply a base path option to the library and download a specific ZIP file containing the assets. The steps below explain this in detail.

Downloading the Assets ZIP File

We provide a ZIP file with all the necessary assets for self-hosting. You can download this ZIP file here.

Extracting and Serving the Assets

After downloading the ZIP file, extract its contents to a directory on your web server. For example:

unzip document-authoring-1.0.26-assets.zip -d /var/www/html/document-authoring/

This will extract the assets to /var/www/html/document-authoring/, where your web server can serve them. This will depend on your individual setup and the kind of web server or reverse proxy being used.

Updating Your Application to Reference the Assets

Now, update your application to load the assets from your server instead of the default CDN. You can provide a base path when initializing the Document Authoring library:

import DocAuth from '@pspdfkit/document-authoring';

const docAuthSystem = await DocAuth.createDocAuthSystem({
	assets: {
		// Replace '/document-authoring/' with the path where the assets are available.
		base: '/document-authoring/',
	},
});

Enabling Offline-First Functionality (Optional)

To support offline-first usage, you can leverage service workers. If your application already uses a service worker, ensure that it caches the Document Authoring assets.

Here’s an example using the Workbox library:

import { registerRoute } from 'workbox-routing';
import { CacheFirst } from 'workbox-strategies';

registerRoute(
	new RegExp('https://yourdomain.com/document-authoring/.*'),
	new CacheFirst({
		cacheName: 'document-authoring-assets',
	}),
);

This will cache the Document Authoring assets locally on the user’s device, enabling full offline access.

Testing and Verification

After setting up the self-hosted assets, thoroughly test your application to ensure that:

  • All assets are loading correctly.

  • There are no cross-origin resource sharing (CORS) issues if your assets are served from a different domain.

  • The application functions as expected both online and offline (if offline-first is enabled).

Maintenance

Keep the following in mind for maintenance:

  • Updates — When updating @pspdfkit/document-authoring to a new version, remember to update the self-hosted assets on your server.

  • Caching — Implement appropriate caching strategies (e.g. cache busting) to ensure users receive the latest versions of your assets.

We hope this is helpful. Contact us if you need any further assistance.