> 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/get-started/samples/fast-viewing.md).

# Viewer optimized PDFs

See a side-by-side comparison of a PDF viewer rendering an unoptimized PDF vs an optimized PDF using this JavaScript sample. Optimized PDFs render in viewers faster, giving users access to even large

See a side-by-side comparison of a PDF viewer rendering an unoptimized PDF vs an optimized PDF using this JavaScript sample. Optimized PDFs render in viewers faster, giving users access to even large and complex PDF documents in seconds. This sample works on all browsers (including IE11) and mobile devices without using plug-ins. Learn more about our [Web SDK](/web/get-started/guides.md).

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

```js
const FILES = {
  'demo-annotated.pdf': ['../../../samples/files/demo-annotated-non-optimized.pdf', '../../../samples/files/demo-annotated.pdf'],
  'construction-drawing-final.pdf': ['../../../samples/files/construction-drawing-final.pdf', '../../../samples/files/construction-drawing-optimized.pdf'],
  'cheetahs.pdf': ['../../../samples/files/cheetahs-non-optimized.pdf', '../../../samples/files/cheetahs.pdf'],
  'magazine.pdf': ['https://pdftron.s3.amazonaws.com/downloads/pl/magazine.pdf', 'https://pdftron.s3.amazonaws.com/downloads/pl/magazine-optimized.pdf'],
  'webviewer-demo.pdf': ['https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf', 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo-optimized.pdf'],
};

const _selected = localStorage.getItem('__selectedFiles');
const _selectedFiles = FILES[_selected];

const firstPdf = _selectedFiles ? _selectedFiles[0] : null;
const secondPdf = _selectedFiles ? _selectedFiles[1] : null;
const firstPdfUrl = localStorage.getItem('__firstPdfUrl');
const secondPdfUrl = localStorage.getItem('__secondPdfUrl');
const isFullAPI = localStorage.getItem('__isFullAPI') || false;

let sourceOne;
let sourceTwo;

if (firstPdfUrl && secondPdfUrl) {
  document.getElementById('url').value = firstPdfUrl;
  document.getElementById('url2').value = secondPdfUrl;
  sourceOne = firstPdfUrl;
  sourceTwo = secondPdfUrl;

  document.getElementById('select1').value = undefined;
} else {
  const defaultSelected = 'cheetahs.pdf';
  const _selectedFiles = FILES[defaultSelected];
  sourceOne = firstPdf || _selectedFiles[0];
  sourceTwo = secondPdf || _selectedFiles[1];

  document.getElementById('select1').value = _selected || defaultSelected;
}
document.getElementById('isFullAPI').checked = isFullAPI;

const timerOne = Date.now();
const timerTwo = Date.now();

// ============== WebViewer setup =============
WebViewer(
  {
    path: '../../../lib',
    initialDoc: sourceOne,
    fullAPI: isFullAPI,
  },
  document.getElementById('middlePanel')
).then(instance => {
  instance.Core.documentViewer.addEventListener('documentLoaded', () => {
    const timerOneFinish = Date.now();
    console.log('The first viewer', timerOneFinish - timerOne);
  });
});

WebViewer(
  {
    path: '../../../lib',
    initialDoc: sourceTwo,
    fullAPI: isFullAPI,
  },
  document.getElementById('leftPanel')
).then(instance => {
  instance.Core.documentViewer.addEventListener('documentLoaded', () => {
    const timerTwoFinish = Date.now();
    console.log('The second viewer', timerTwoFinish - timerTwo);
  });
});

// ============== End WebViewer setup =============

// ============== Setup input controllers =============
document.getElementById('selectControl').onclick = e => {
  e.preventDefault();
  const select1 = document.getElementById('select1');
  const selected = select1.options[select1.selectedIndex].value;

  localStorage.setItem('__selectedFiles', selected);
  localStorage.removeItem('__firstPdfUrl');
  localStorage.removeItem('__secondPdfUrl');
  location.reload();
};

document.getElementById('url-form').onsubmit = e => {
  e.preventDefault();
  const firstPdf = document.getElementById('url').value;
  const secondPdf = document.getElementById('url2').value;

  localStorage.setItem('__firstPdfUrl', firstPdf);
  localStorage.setItem('__secondPdfUrl', secondPdf);

  localStorage.removeItem('__selectedFiles');
  location.reload();
};

document.getElementById('isFullAPI').onchange = e => {
  if (e.target.checked) {
    localStorage.setItem('__isFullAPI', true);
  } else {
    localStorage.removeItem('__isFullAPI');
  }
};
```

{% 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/get-started/samples/fast-viewing.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.
