# Server side range request sample code in javascript/angular

**URL:** <https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [November 7, 2024, 10:39am UTC](https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510 "2024-11-07T10:39:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prajneshu.khandavall](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@prajneshu.khandavall](https://pdfjs.community/u/prajneshu.khandavall)\
**Post date:** [November 7, 2024, 10:39am UTC](https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510/1 "2024-11-07T10:39:01Z")

</div>

**Which product are you using?**  
PDF.js Express Plus

**PDF.js Express Version**  
8.7.2

**Detailed description of issue**  
We have been using pdf js plus viewer, loading large pdf (500+ pages) viewer taking long time to load. is there any sample javascript code to implement server side/range request?

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [November 7, 2024, 8:02pm UTC](https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510/3 "2024-11-07T20:02:13Z")

</div>

Hello prajneshu.khandavall,

Supporting range requests is a server setting on your file server. Take a look at this guide here for more information: [Best-practices | Apryse Documentation](https://docs.apryse.com/web/guides/best-practices/#support-range-requests)

Best regards,  
Tyler

---

<div class="post-metadata">

**Author:** ![ashokkumar.kunchala](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ashokkumar.kunchala](https://pdfjs.community/u/ashokkumar.kunchala)\
**Post date:** [November 22, 2024, 9:15am UTC](https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510/4 "2024-11-22T09:15:38Z")

</div>

Hi Tyler,

We are encountering an issue with range requests when trying to open large files using PDF.js Express in the browser. For some files, the range requests are working perfectly fine, but for others (both 40MB and 180MB files), the fourth range request fails, leading to an error.

Here is a detailed breakdown of the issue:

### **File Details:**

- **File 1:** 40MB PDF file (Successful with custom code, but fails in PDF.js Express)
- **File 2:** 180MB PDF file (Fails in PDF.js Express)

### **Observed Behavior:**

- For both the 40MB and 180MB files, PDF.js Express sends four range requests:
  1. The first request is for the entire file, and it successfully retrieves the content.
  2. The second, third, and fourth requests are for specific byte ranges, but **the fourth range request fails** with a **400 error** (`ConditionalHeadersNotSupported` or similar).The network tab in the browser shows these four requests, where the first three successfully return content, but the fourth request fails.

### **Custom Code Behavior:**

- We tested with custom code using node js (outside of PDF.js Express) to download the same 40MB and 180MB files. The custom code successfully handled the range requests without any issues and was able to download the files in parallel chunks.

### **Issue with PDF.js Express:**

- When using PDF.js Express to display the PDF files (both 40MB and 180MB), the range requests fail after the fourth request with a **400 error** , and the file is not opened in the viewer.
- The range requests being made by PDF.js Express are not identical to the ones handled by my custom code.
- For some files, the first three range requests succeed, but the fourth request results in an error like:

```javascript
400 Error: ConditionalHeadersNotSupported

```

### **Additional Information:**

- The issue occurs **only for large files** , and I believe this might be related to how PDF.js Express handles the range requests automatically in the background.
- When tested with smaller files, the range requests succeed without issue.

### **Questions:**

- Is there a configuration or setting within PDF.js Express that can help resolve this issue for larger files?
- Could this be related to how PDF.js Express handles conditional requests or range request headers for large files?

Any insights or suggestions would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 22, 2024, 6:54pm UTC](https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510/5 "2024-11-22T18:54:15Z")

</div>

Hi there,

Are you able to reproduce the issue on the demo?

> **[PDF.js Viewer Demo | PDF.js Express](https://pdfjs.express/demo)**
>
> Try the PDF.js Express Viewer demo: 26 out-of-the-box annotations, PDF form filling, e-signatures, UI customization, light/dark themes & more.

Could you please share the input files and the HAR file?  
Have you also linearized the PDF files?

> **[PDF.js Express Viewer Integration Best Practices | Documentation](https://pdfjs.express/documentation/learn-more/best-practices#linearize-pdf-files)**

Best regards,  
Kevin

---

<div class="post-metadata">

**Author:** ![ashokkumar.kunchala](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ashokkumar.kunchala](https://pdfjs.community/u/ashokkumar.kunchala)\
**Post date:** [November 25, 2024, 5:50pm UTC](https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510/6 "2024-11-25T17:50:42Z")

</div>

Hi Kevin,

Yes we are able to replicate the same in DEMO as well  
please find the attached screenshots for the same

 ![S1](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/6/6256fbfb13a541afa0d0aac378ad22d1476496f8.png)  
 ![S2](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/b/bd79e75ce9998387d7b4650f148a511a1a1f6cee.png)  
 ![S3](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/b/b7c47417eb559fc8e3579b51d24aa8575b052697.png)

URL of the file for your reference : [File Link](https://anvesadevstorageaccount.file.core.windows.net/dtsearchfileshare/anvesaclients/anvesacontainerization/20200212%20Production/Searchable%20PDfs/20200212%20Production/1002/IMAGES/IMG00001/DocumentParts/BRS00002798_001.pdf?sv=2023-11-03&spr=https%2Chttp&st=2024-11-25T17%3A34%3A25Z&se=2024-11-30T17%3A34%3A00Z&sr=f&sp=r&sig=4untVo0lIuv06lwb4XaLkRShnXGvF%2ByjbsFdEmR7C7U%3D)

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [November 25, 2024, 9:53pm UTC](https://pdfjs.community/t/server-side-range-request-sample-code-in-javascript-angular/3510/7 "2024-11-25T21:53:28Z")

</div>

Hi there,

Thank you for the file url, I was able to reproduce the issue.

It looks like this is a common issue coming from Azure, please see this forum post for possible solutions:

> <https://stackoverflow.com/questions/43706605/azure-file-storage-error-condition-headers-are-not-supported>

Best regards,  
Kevin Kim
