> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/best-practices/preload-worker-files.md).

# Preloading WebViewer library/worker files

Learn how to optimize WebViewer with the initialDoc option to efficiently load large library resources like PDF or Office workers. Preload workers upfront for seamless file processing and display on s

When WebViewer is loaded with the `initialDoc` option, it will first load the large library resources, like PDF or Office workers, depending on the type of file you are trying to open, and then the file will be processed and displayed on the screen.

By default WebViewer will load the worker files lazily when needed but if WebViewer needs to be initialized without opening a file or if you will be loading both PDF and Office files, you can use the `preloadWorker` option to load the workers up front.

{% hint style="info" %}
It is not recommended to use this option when WebViewer Server is enabled as certain clients (IE, mobile devices) will not want to load the PDF workers at all for performance reasons.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  path: '../../../lib',
  preloadWorker: 'pdf',
  ...
}, document.getElementById('viewer'))
  .then(instance => {
      // ...
  });
```

{% endcode %}
{% endtab %}
{% endtabs %}

Here WebViewer is displayed without opening a file but the PDF workers have still been loaded.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-f130c30c46b678d19d6ca1c5f2726422290bf482%2F1256fc6bdeb8456d579141a7210848daf73554d6-1000x756.png?alt=media)

## Preload MS Office workers

The MS Office workers are preloaded in the same way as PDF workers, you only need to change the `preloadWorker` option to "office". If you decide to preload both PDF and Office workers on the initial load change it to "all".

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  path: '../../../lib',
  preloadWorker: 'office', // 'all' to preload both pdf & office workers
  ...
}, document.getElementById('viewer'))
  .then(instance => {
      // ...
  });
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/best-practices/preload-worker-files.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
