Pdf.js: Remove PDF cache history in PDF.JS

Created on 8 Jul 2015  路  3Comments  路  Source: mozilla/pdf.js

Sir,
We are working on e-library where pdf.js is used to load the PDF files chunk by chunk. The file size of PDF is normally 16MB. AT first load of PDF.JS(disabling cache on browser), the pdf is downloaded in chunk. But as I refresh the page(withour disabling chache on browser), the PDF.Js downloads whole PDF instead of chunk.
For reference,
Browsing pdf with (cache disable):
working snap

But when the same PDF is stopped in the middle and reloaded again then, whole pdf is downloaded as:
not working snap

How can I make PDF.JS load the PDF file downloading chunk-by chunk even if I refresh the page multiple times?

Most helpful comment

One way to disable caching client-side is to add a random or timestamp-based parameter to the end of the URL, e.g. viewer.html?file=some.pdf&_=someRandomNumberOrCurrentDatetime. This will cause the browser's cache to be bypassed, because the URL is always different.

All 3 comments

Is there any server-side configuration required to resolve this issue? It would be helpful enough if one could provide the necessary configurations on: SERVER or CLIENT so that the PDF would be loaded same as like as mozilla hosted PDF.JS( Every request is made with 206 Partial Content).

Is there any server-side configuration required to resolve this issue?

Yes, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching_FAQ for solution. PDF.js is using browser's XHR and has no direct control over request caching. Closing as answered.

One way to disable caching client-side is to add a random or timestamp-based parameter to the end of the URL, e.g. viewer.html?file=some.pdf&_=someRandomNumberOrCurrentDatetime. This will cause the browser's cache to be bypassed, because the URL is always different.

Was this page helpful?
0 / 5 - 0 ratings