PDF wasm libraries are getting loaded twice

WebViewer Version: 8.1.0

Do you have an issue with a specific file(s)? Yes.
PDFNetCWasm.br.wasm is getting requested and downloaded twice.

Can you reproduce using one of our samples or online demos? Yes!
Using the official webviewer-angular-sample (see link in minimal sample below, I can only provide two links as a new user o.O ), installing packages and serving the app with ng serve shows exactly the same behaviour. (No matter if I change webviewer version to 8.1.0 or leaving it ot the default installed version of 8.9.0)

Are you using the WebViewer server? No.

Does the issue only happen on certain browsers? It does at least happen on Firefox (105) and Chrome (106). Also for the above mentioned webviewer sample.

Is your issue related to a front-end framework? No other than pdftron/webviewer.

Is your issue related to annotations? No.

Please give a brief summary of your issue:
Instantiating webviewer in client mode only within angular results in PDFNetCWasm.br.wasm being downloaded twice.

Please describe your issue and provide steps to reproduce it:
Since it is reproducible with PDFTrons own sample, I will refer again to the official sample webviewer-angular-sample, see below.

Depending whether you enable Office Docs and/or full API this extra downloads are getting very large, downloading them twice obviously making it worse.
It does not matter if we preload (preloadWorker: 'pdf') or load them on demand. What one can see that the initiator of those requests are different, but I cannot debug that properly since the issuing lib is scrambled. Here are shortened version of the tracebacks:

f	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:56
f	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:56
self.Module.instantiateWasm	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:71
createWasm	@	4389c65f-507f-488a-9b10-cb3b9812bd0c:1
Module.asm	@	4389c65f-507f-488a-9b10-cb3b9812bd0c:1
(anonymous)	@	4389c65f-507f-488a-9b10-cb3b9812bd0c:1
c	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:72
l	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:211
(anonymous)	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:212
(anonymous)	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:223

and

t	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:50
q	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:53
e	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:53
r	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:54
f	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:56
(anonymous)	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:56
Promise.catch (async)		
f	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:56
f	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:56
self.Module.instantiateWasm	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:71
createWasm	@	4389c65f-507f-488a-9b10-cb3b9812bd0c:1
Module.asm	@	4389c65f-507f-488a-9b10-cb3b9812bd0c:1
(anonymous)	@	4389c65f-507f-488a-9b10-cb3b9812bd0c:1
c	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:72
l	@	PDFworker.js?isfull=true&disableLogs=0&wasm=1:211

I hope someone knows how to resolve this… thanks in advance!

Please provide a link to a minimal sample where the issue is reproducible:
GitHub - PDFTron/webviewer-angular-sample: Sample to demonstrate integrating WebViewer into Angular :slight_smile:

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi,

Thank you for contacting WebViewer Support. This is probably due to your server not being configured to send the .wasm module with the correct content-encoding. You can see this guide for more information

The first request is an attempt to streaming compile the WebAssembly which fails because the content encoding was not configured. That said even without server configuration, caching will usually kick in for this case and avoid a second download. In your case, you probably have caching disabled in your browser network tab, so it downloads the file twice instead of using the cache data

Best Regards,

Andrew Yip
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

@Andrew_Yip
Hey Andrew
On nginx, is there any solution on this problem?
looking through the document on official site and github as well, it didn’t find the solution for nginx

Hello Paul,

The main goal is to serve files within WebViewer containing “.gz.” in their file name with Content-Encoding: gzip and files containing “.br.” in their file name with Content-Encoding: br. You should be able to follow the nginx guides on setting content encoding to work with gz and br encoding

http://nginx.org/en/docs/http/ngx_http_gzip_module.html

If you are still having issues, would it be possible to see get screenshot of your network tab or HAR file of the content encoding being used by your server? Thank you

Best Regards,

Andrew Yip
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

@Andrew_Yip
Hey, Andrew
Few more questions, we use cloudflare and enable the brotli setting but still load the module twice
I check the content-encoding on our url, br and gzip is ok I think

截圖 2023-01-12 下午12.40.06

I also try to add the application/wasm wasm to mime.types, but in network tab it will disappear when loading done

So in the end I remove the application/wasm wasm in the mime.types, the screenshot in our network tab as below

Please help to check. Thank you!!

Hello paul.chen,

I think the twice loading files is probably a integration issue, can you please provide a sample project to reproduce this issue

Best regards,
Tyler

Hi paul.chen,

An integration issue meaning setup with the server hosting the files, that or somehow there is a secondary request being called by the client.

If you could provide a testing environment that would be fantastic, thank you!

Best regards,
Tyler

Hello paul.chen,

I am unable to reproduce that issue as well. Please provide a sample or testing environment where I can check it out.

Best regards
Tyler