Appearance
Lazy Loading >=4.5.0
Vue PDF Viewer lazy-loads pages. It shows the first page as soon as it is ready and loads the rest as needed, so documents open quickly and scroll smoothly.
How It Works
When the PDF is loaded from a URL, the viewer:
- Read the size of page 1 and uses it as an estimate for every other page
- Display the document right away, using those estimated sizes to lay out the scrollable area
- Load the real pages in the background and as they scroll into view, correcting each page's size once it is known
If a document mixes page sizes (for example, portrait and landscape pages), you may see a brief layout adjustment as estimated pages are replaced by their actual sizes. The Vue PDF viewer keeps the page you are reading in place while this happens.
Navigating with initialPage, the page input, or thumbnails waits until the target page has its real position.
Thumbnails for pages that have not loaded yet show a placeholder until the page is available.
Which Sources Load Lazily
| Source | Lazy loading |
|---|---|
URL string, e.g. src="https://example.com/file.pdf" | Yes |
URL object | Yes |
{ url: ... } or { range: ... } | Yes |
ArrayBuffer, Uint8Array or other typed array | No. The data is already in memory, so all pages are read up front |
{ data: ... } | No |
Server Requirements
Lazy loading saves bandwidth only if the server can return part of a file. Without range support, the browser still downloads the whole file, although the first page still appears early.
- The server must support HTTP range requests and respond with
Accept-Ranges: bytes. - If the PDF is on a different origin than your app, the server's CORS configuration must also:
- allow the
Rangerequest header (Access-Control-Allow-Headers: Range), and - expose the range headers (
Access-Control-Expose-Headers: Accept-Ranges, Content-Range, Content-Length).
- allow the
You can tune the size of each range request with rangeChunkSize.
Loading Only What Is Viewed
By default, the viewer keeps fetching pages in the background after the document opens so later pages are ready before the user reaches them. To load pages only as they scroll into view, for example on metered connections, set disableAutoFetch:
vue
<script setup lang="ts">
import { VPdfViewer, type PDFDocumentOptions } from "@vue-pdf-viewer/viewer";
const documentOptions: PDFDocumentOptions = {
disableAutoFetch: true
// disableStream defaults to true when disableAutoFetch is true
};
</script>
<template>
<VPdfViewer src="https://example.com/file.pdf" :document-options="documentOptions" />
</template>When disableAutoFetch is true and disableStream is not set, the viewer also turns off streaming. Otherwise the server would still send the entire file. Set disableStream: false explicitly if you want streaming on anyway.
WARNING
Features that read every page still download the whole file, even with disableAutoFetch. These include searching the whole document, printing, downloading, and plugins that request the original file bytes.
Related Behavior
- Search: Results appear progressively while the PDF loads. See Search Controller.
- Network recovery: If the connection drops and returns, missing pages load again without emitting
loaded. See Events.