"splintering" HTTP requests

Currently, I am working on an Angular application that retrieves data from a REST server. Each piece of data we retrieve contains essential "core" information for basic representation, as well as additional "secondary" data like comments and other optional details that users may or may not want to see.

I am striving to optimize our request process in order to reduce the time users spend waiting for a loading spinner to complete. Initially, fetching all core and secondary data simultaneously results in a slow response time, but only retrieving the essentials until a user requests more data can lead to unnecessary delays if they end up needing it while reading the initial content.

As of now, my approach involves pulling core content first and then triggering a secondary data retrieval after the success callback from the initial request. While this is still experimental, I am curious about any established best practices in this scenario. (I could certainly search online for answers, but I'm unsure of what specific keywords to use, hence the quotes in the title of this question)

One specific question I have is whether it's better to initiate numerous small HTTP transactions or a few large ones. My inclination leans towards multiple small requests, especially if I can predict which additional data users are most likely to need promptly. However, I wonder if there is a threshold where this approach becomes less efficient. Am I on the right track with this strategy, or should I reconsider my thinking altogether?

Answer №1

My strategy mirrors yours, and it proves to be quite effective for handling a substantial collection with many keys, totaling over 10,000 items.

The pagination of the collection is managed using ui.bootstrap.pagination, showing only 10 items at any given time. Users can search based on title.

To optimize efficiency, I fetch just the id and title initially for the entire collection so that searches can be executed promptly.

Additionally, I make use of a $watch on the array containing the displayed items to trigger a secondary pull for their complete details, but this action occurs only when the array undergoes changes. This way, in the most extreme scenario, detailed information for only 10 items needs to be retrieved.

Results are stored in cache for improved performance, showcasing immediate outcomes thanks to the proactive nature of the $watch.

Is it more advantageous to carry out numerous small HTTP transactions or opt for a few large ones?

I find that executing larger transactions for selected items (those clickable on the screen) offers optimal efficiency.

In terms of adhering to best practices: While there may be multiple approaches to achieving desired objectives,

your current method is highly effective as it acquires only necessary data precisely when needed
. Moreover, its implementation is straightforward.

Similar to your initial assumptions, I too previously believed that several smaller pulls would be preferable over fewer large ones. However, after receiving advice to prioritize larger pulls in response to a query like this one: Fetching subdocuments with angular $http

Answer №2

When it comes to finding the right keywords for your search, I recommend looking into:

dynamic content loading

Another option is utilizing websockets and real-time data streaming: Oboe.js is a great tool for this purpose with its excellent functionality:

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

Encountering issues with resolving dependencies in webdriverIO

I'm attempting to execute my WebdriverIo Specs using (npm run test-local) and encountering an error even though I have all the necessary dependencies listed in my package.json as shown below: [0-2] Error: Failed to create a session. Error forwardin ...

Retrieving data in [slug].js using Reactjs

I am currently working on a project in Reactjs utilizing the "nextjs" framework. I have successfully managed to retrieve data (specific blog details) based on the slug([slug.js]). However, I now need to display data from all other blogs within the same c ...

When an import is included, a Typescript self-executing function will fail to run

Looking at this Typescript code: (()=> { console.log('called boot'); // 'called boot' })(); The resulting JavaScript is: (function () { console.log('called boot'); })(); define("StockMarketService", ["require", "exp ...

`I'm having difficulty transferring the project to Typescript paths`

I posted a question earlier today about using paths in TypeScript. Now I'm attempting to apply this specific project utilizing that method. My first step is cloning it: git clone <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cf ...

Utilize a variable within an HTML attribute

Currently utilizing Angular and I have the following HTML snippet <input onKeyDown="if(this.value.length==12 && event.keyCode!=8) return false;"/> Is there a way for me to incorporate the variable "myNum" instead of the ...

In the realm of JavaScript, what happens when a function yields yet another function while also welcoming another function as an argument?

After following a Node & Express project tutorial on YouTube, I encountered the following code snippet in an async JavaScript file: const asyncHWrapper = (fn) => { return async (req, res, next) => { try { await fn(req, res, next); } c ...

Is there someone who can explain to me the process behind this?

(function(ng, app){ app = angular.module('app', []); app.config(function($provide) { $provide.constant('town', 'Burlington'); }); app.constant('name', 'Rob F.'); app.controlle ...

Which types of characters am I allowed to include in an HTTP response body while using NodeJS and Express?

I am currently developing a node express app that responds to an AJAX post from the client browser. I am curious about what characters would be considered invalid to include in the HTTP response body. My response header specifies the use of charset=utf-8, ...

jQuery code runs smoothly on Firefox but encounters issues on Chrome

I'm experiencing an issue with a script that is supposed to post a comment and load the answer from a server. The script works fine in Firefox, but in Chrome, it seems that no event is triggered. You can click the button, but nothing happens. I'v ...

The JSON key has been labeled as "valid", making it difficult to access in JavaScript as demonstrated in a JSfiddle example

Initially, I transformed a Plist file (XML formatted) into JSON using an online tool. Extracting the important data from this extensive JSON file was not a challenge. Utilizing this crucial data, I am reconstructing a new JSON file that is concise and cont ...

Modifying the id attribute dynamically using jQuery during runtime

In my project, I have a submit button with the id of "submit" that is used to save new records. // Function to add a new customer record $("#submit").click(function() { var data = $.param($("#form").serializeArray()); ...

Attempting to display the todo item in the form of <li>, however, the todo.name property is not

I am currently developing a task manager application and have encountered a puzzling issue: When I include the Todo component within the TodoList component and pass the todo item as a prop todo = {name: "ssss", status: false, id: 0.0289828650088 ...

Failure to maintain a persistent connection with System.Net.Http.HttpClient on specific servers

Currently diving into the Heroku API with the .NET System.Net.Http.HttpClient. I'm specifically looking to get keep-alive functioning so I can streamline the process of sending numerous HTTP requests through a single TCP connection, avoiding multiple ...

Exploring the Use of Tab Navigation and Carousel Functionality with Angular

Seeking guidance on how to incorporate tabs and a carousel within those tabs using Angular JS. I am a beginner with Angular JS and struggling with implementing routing within tabs. Any help with code examples would be greatly appreciated. Additionally, I ...

Exploring the process of setting up reactive forms with AngularJS to handle arrays

I am working on setting up a reactive form for AngularJS and need to initialize certain fields: initializeBusinessEposForm(): void { this.businessEposForm = this.formBuilder.group({ custom_pos_priority: new FormControl(false), custom_float_ ...

Exploring the near method to Parse.Query a class

I'm currently working on my first iOS application, which allows users to add annotations to a map for others to view. In this project, I have decided to utilize Parse as the backend service. What I already have: There is a class called "Pins" in Par ...

Delay in Updating Nativescript Slider Value

After developing a metronome using the Nativescript Slider here to adjust speed (interval), I encountered an issue with incorrect updating of values. The code initially worked well, allowing real-time speed changes: app.component.html <Slider #sl min ...

How to implement a select all feature using React and MaterialUI

I am facing a challenge with managing multiple sets of checkboxes independently along with a toggle that can switch them all on or off within their respective groups. Each checkbox has two states, and I can identify the checkbox being clicked using event.t ...

JavaScript checking the current page's URL is crucial for maintaining accurate and dynamic

I've attempted to verify the URL using this specific function. It functions properly with single text, but fails when a URL is inputted. jQuery(document).ready ( function () { //var regExp = /franky/g; //It works fine ...

The process of locating a textarea by its id becomes obsolete when integrating CKEDITOR

The data table has editable cells, where clicking on a cell will trigger a bootstrap modal to display with a textarea containing the text retrieved from the database. Snippet of the table structure: <table class="table table-striped table-hover" id="t ...