Resolving Limited Resources Error in Chrome

I have a JavaScript library that manages the downloading of JPEG images for clients asynchronously. However, when dealing with a large number of images, say around 5000, Chrome browser tends to throw an "ERR_INSUFFICIENT_RESOURCES" error during the AJAX request.

Unfortunately, each image must be requested individually as there is no option to bundle them on the server-side.

What solutions can I consider to circumvent this issue? It's worth noting that the download functions perfectly in Firefox...

Below is the code snippet for the current download process:

function loadFileAndDecrypt(fileId, key, type, length, callback, obj) {     

 var step = 100 / length;

 eventBus.$emit('updateProgressText', "downloadingFiles");

  var req = new dh.crypto.HttpRequest();
    req.setAesKey(key);
    let dataUrl;
    
    if (type == "study")  {
         dataUrl = "/v1/images/";
    }else {
         dataUrl = "/v1/dicoms/";
    }    

    var url = axios.defaults.baseURL + dataUrl + fileId;
    req.open("GET", url, true);
    req.setRequestHeader("Authorization", authHeader().Authorization+"")
    req.setRequestHeader("Accept", "application/octet-stream, application/json, text/plain, */*");
    req.responseType = "arraybuffer";

    req.onload = function() {
        console.log(downloadStep);    
        downloadStep +=  step;
        eventBus.$emit('updatePb', Math.ceil(downloadStep));

        var data = req.response;
        obj.push(data);
        counter ++;        
        //last one
        if (counter == length) {        
            callback(obj);        
        }
    };

    req.send();
}

Answer №1

Your error message is indicating that your code may be using up too much memory, or possibly hitting a limit on the number of pending requests. To prevent this issue, consider having your frontend request batches of 5000 individual images at a time and manage the flow of requests carefully. It's not ideal to download all 5000 images separately; instead, bundle them together for easier retrieval. If you are looking to display the images on the frontend, linking to them statically or dynamically would be a more efficient approach 😉

Answer №2

Develop a class called FileRequester:

  • Accepts the file-Id (image that needs to be downloaded) as an argument
  • Capable of executing the HTTP API request
  • Able to store the result of the request

Instantiate an array of objects from this class for downloading multiple file-Ids.

Save the array in a DownloadManager which can initialize and oversee the downloads:

  • Download files in batches, for example by sending out 5 requests at a time before proceeding with the next batch
  • Stop downloads after encountering multiple failures
  • Adjust batch size based on bandwidth availability
  • Halt download when authentication expires and resume upon authentication refresh
  • Provide the option to retry failed downloads from previous attempts

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving information from a MySQL database through Ajax

I need help with calculating the sum of prices sold between two specific dates. My query seems to be working fine in the database, but when I use it in PHP, it returns nothing. Here is my code: <html> <body> <script language="javascript" ty ...

Implementing dynamic selection of items in a drop-down list with Ruby On Rails using Ajax (once more)

Help needed! I am so close yet so frustrated. Here are the two drop-down lists on the products/new page: <p> <%= f.label :category_id %>: <%= f.select("category", Category.find(:all).collect {|c|[c.name, c.id]}) %> </p> <% ...

When Typescript compiles to JavaScript, it may result in code that appears to be a function

In the following typescript code snippet: export enum UID { FACTORY, ROBOT } we see how it compiles to javascript: (function (UID) { UID._map = []; UID._map[0] = "FACTORY"; UID.FACTORY = 0; UID._map[1] = "ROBOT" ...

A guide on transferring a variable from one page to another using PHP

I am having trouble passing the button ID to another page when my dynamically created button is clicked. I tried passing it but it did not work as expected. Can anyone provide a solution? Below is the code snippet from dash.php: <?php session_start( ...

Implementing Google Maps JS API with Inertia.js server-side rendering: A beginner's guide

Setting up server-side rendering for my Vue.js SPA using Inertia and Laravel has been a challenge. Every time I attempt to load a page with a Map, an error from the SSR server process occurs: [Vue warn]: Unhandled error during execution of setup function ...

Is it unnecessary to mention both JavaScript and AJAX together?

During a recent conversation I had, someone mentioned that it is inaccurate to state that since Ajax is JavaScript. The scenario was: "How can I perform an action on a webpage without requiring a page refresh?" My response: "Utilize JavaScript along wi ...

JavaScript is unable to create an Object for the ActiveX control, resulting in a 429 error

Recently, I developed an ActiveX control named ZPLPrint.cs which I then compiled into a dll using the csc command in the .Net 4.xxx directory. Following that, I registered the dll with the command regasm ZPLPrint.dll /tlb /codebase. My setup includes utili ...

Angular allows for the creation of dynamic content, much like the append function in jQuery

I am currently working with Angular to create a dynamic star rating system. I have implemented a function to generate the code for the stars dynamically, but unfortunately, they are not showing up on the page. Can anyone help me troubleshoot this issue? B ...

What methods can be used to save mouse coordinates to a remote server?

As a beginner in server-side programming, I have some questions regarding my project built in JavaScript and Node.js. The current functionality involves sending mouse coordinates to the server and redrawing them on every client's screen. However, new ...

Using React JavaScript to access an Axios API and retrieve a surf object array in JSON format

When using Axios to call an example API in React, my goal was to render a specific field from the array. For instance, I wanted to display only the company name of the first person in the output - "person[0].company.name". However, instead of getting "Roma ...

Tips for effectively launching a new window after a successful JQuery AJAX call

My goal is to have a dynamically generated link open after an ajax request, specifically once the success response is returned. I've managed to get it working on desktop Chrome and Firefox, but unfortunately, it doesn't work as expected on mobile ...

Uncaught jQuery onchange event not firing

I am facing an issue with a drop-down list inside a data grid on the main page. When values are changed, a popup should display and the values from the popup need to be sent back to the main page. However, I am having trouble triggering the onchange event. ...

Turn off all VuetifyJS transitions

Is there a way to completely turn off all transitions, such as the slide-x-transition or dialog modal scale transition, in VuetifyJS? ...

Data not being received by script via AJAX request

I have been encountering issues with my AJAX implementation. The JSON data that I am trying to send to process.php is not being received. Despite going through numerous articles and forums, I have been unable to find a solution. Below are the key snippets ...

What steps are needed to integrate the FreshworksWidget in a next.js project?

When referring to the Freshdesk documentation, there is a provided script that looks like this: <script> window.fwSettings={ 'widget_id':12000000025, 'locale': 'en' }; !function(){if("function"!=typeof w ...

Struggling to align legacy reCaptcha code

I need help centering an old reCaptcha code within a form, but my attempts have not been successful. Here is what I have tried: margin:0 auto; margin:0 auto !important; text-align:center; This is the HTML code I am working with: <p class="captcha"&g ...

Clicking is applied to the <tr> element, where there is also a button with an onclick event

How can I prevent the onClick event on a tr element when there is a button inside the tr that also has its own onclick event? <tr key={index} onClick={() => this.getDetailPage(jobsData)}> <td>{serial_num}</td> <td>{jobsData ...

Trouble with Sum Array Function

I've encountered an issue while trying to calculate the sum of a dynamic array. Instead of adding up the numbers, they are just being displayed next to each other. I attempted to sum 1+2+3+4+5, but the output shows as 012345 instead of 15. let userIn ...

Certain iFrame instances are unable to display specific cross-domain pages

I'm currently working on a project to create a website that can embed external cross-domain sites, essentially like building a browser within a browser. I've been experimenting with using iFrames for this purpose: While it works for some pages, ...

Error encountered when attempting to export a TypeScript class from an AngularJS module

In my application using Angular and TypeScript, I have encountered a scenario where I want to inherit a class from one module into another file: generics.ts: module app.generics{ export class BaseClass{ someMethod(): void{ alert(" ...