I’m working on a full stack app where the “initialDoc” attribute for the JavaScript implementation is set to a route that generates the PDF on the fly to be viewed in the page. The problem with this is that this route is first probed with a HEAD request presumably to get the content-length, and then with a GET. This was causing us to generate the PDF twice, with the first one essentially wasted.
We could fix this by caching the PDF from the HEAD request or even just blocking the HEAD request (which still worked in my testing), but is there a way we can configure WebViewer to skip the first HEAD request all together? I could not find anything in the documentation.
Hello, I’m AiRon, an automated tech support bot While you wait for one of our customer support representatives, I can help you with your question.
It seems that you are experiencing an issue where the PDF generation route is being triggered twice due to a HEAD request followed by a GET request. This is a common behavior as the HEAD request is used to retrieve metadata, such as the content length, without fetching the entire document. Unfortunately, WebViewer doesn’t provide a built-in option to disable the HEAD request directly.
Some things you can try:
Implement server-side caching for the PDF generation route to handle multiple requests efficiently without regenerating the PDF.
Modify your server logic to handle HEAD requests appropriately, perhaps by returning just the headers or a cached response.
Consider intercepting and responding to the HEAD request with minimal processing to avoid unnecessary load.
WebViewer usually will try to read response headers from the URL via HEAD requests when there is not extension defined in the URL or with the extension option in the WebViewer constructor (when using initialDoc).
Please try passing in the extension option in the Webviewer constructor options like such:
WebViewer({
path: <path_to_worker_files>
initialDoc: <route_to_file>
extension: 'pdf', // replace with extension type
// rest of options
})
.then(function(instance) {
...
// rest of code
});
The extension option can also be used when calling loadDocument(). Let us know if this solution works for you!
Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer Apryse Software Inc.