Tips for avoiding XMLHttpRequest from buffering the complete response

Trying to implement an ajax call to a streaming endpoint on my server. Need the connection to accept continuous pushed data from the server, but XMLHttpRequest seems to buffer the entire response. Want the browser client to receive each chunk of data once and move forward.

Looking for a way to stop this behavior. Any solutions?

UPDATE: Discovered that Firefox can handle this by setting XMLHttpRequest.responseType to "moz-chunked-text" or "moz-chunked-arraybuffer". Unfortunately, other browsers don't support this feature. Probably not the most reliable approach anyway.

WebKit equivalent to Firefox's "moz-chunked-arraybuffer" xhr responseType

Answer №1

If you're interested in learning more about Push technology, I recommend checking out this wiki: http://en.wikipedia.org/wiki/Push_technology

It seems like what you might be referring to is long polling, where a server sets its output to chunked. You can find an example of how to make PHP generate Chunked response here.

If your server sends a chunked response, you could use a tool like https://github.com/flowersinthesand/portal to continuously read the stream.

Another option, if you can't change your server's transfer encoding or prefer to stick with Ajax, is to have your client poll the server for updates. Here's a simple example using jQuery:

setInterval(function(){
   $.get("/my/endpoint?last_updated=" + (new Date().getTime()), function(data){
      console.log("Received response");
   });
}, 5000); // Refresh every 5 seconds

In my experience, Socket.io has been very effective. It's based on node.js and optimizes performance for each client by utilizing websockets, flash sockets, and polling as needed to provide fast speeds for newer browsers while still supporting older ones.

Answer №2

Check out this informative link on Comet programming: http://en.wikipedia.org/wiki/Comet_(programming)

My website utilizes Ajax to poll a server while incorporating a Comet Server. When the browser sends a request, it only receives a response when a specific event occurs on the server (such as a file finishing generation). If no response is received after a 30-second timeout, an empty response is sent. Each time the client gets an Ajax response, it promptly sends a new request.

The benefit of this setup is that there's no need to constantly poll the server; instead, the client is instantly notified of any events occurring on the server.

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

How to dynamically assign a value in a React datepicker component in a React application

Having troubles with react-datepicker? I encountered an issue where setting the value of react-datepicker from props caused it to either not show the value or display a 'wrong time format' error. Here is a snippet of the Datepicker code: this.sta ...

Converting SVG to PNG image directly in the browser (compatible with all browsers, including Internet Explorer)

I am currently working with Highcharts and I have a need to convert all the charts displayed on the webpage into images so that I can send them to my server for merging with a master export Excel file. The Excel file already contains some tables and pivot ...

Maintaining clicked links in jQuery and dynamically adding or removing CSS classes upon page refresh

I'm facing an issue with my page that contains multiple "Filters" in the form of links. Whenever a link is clicked, it filters the results accordingly. However, I'm struggling to add or remove a class upon page refresh after clicking a filter lin ...

What is the best way to assign a dictionary value to 'v-model' using a specific key?

Currently, I am working on integrating filterDataArray into my application to dynamically add parameters to my API requests. For this purpose, I have initialized the filterData array as follows: filterData: [ {key: 'name', value: '&ap ...

Sharing information between functions within the same controller in AngularJS

I have been working on a project which involves the use of AngularJS and MVC. I am retrieving status details data using HTTP POST, and now I need to utilize this data in another function of my controller. Despite passing the data in a scope variable named ...

Creating a fixed-size set in React with randomly ordered elements

I am currently working on a project where I need to retrieve a random array from a .json file using React. My goal is to create 16 cards, each displaying a number that appears twice. To ensure uniqueness, I am utilizing a Set, but I am facing an issue with ...

A guide to implementing X-Frame-Options in an express.js web application using node.js

My dilemma involves serving static assets within iframes across various desktop and mobile web clients. Specifically, I am seeking guidance on how to whitelist a select group of origins for allowing the setting of X-Frame-Options headers. This will enable ...

Does ReactJS demonstrate ingenuity when it comes to calling the render method?

Despite not utilizing any of the props supplied to the component, will it still re-render when the props change? class MyComponent extends React.Component { constructor(props) { super(props); const { propValue } = props; // do something wi ...

Unlock the full potential of `enableReinitialize: true` by utilizing the options `destroyOnUnmount: false` and `forceUnregisterOnUnmount: false` in a

I am currently working on a wizard form using redux-form/immutable for creating and updating a form. An issue I'm facing is that when moving from tab1 to tab2 in the wizard form, the state (user inputs) in tab1 gets lost. I have experimented with di ...

JavaScript combined with a dynamic menu, a customized current link style using CSS, and a site built on PHP

Here's my current website setup: My website is modular and uses dynamic inclusion. The header is a crucial part of the main page, which is responsible for displaying content from specific links on the site. External links to CSS and js files are incl ...

An issue has arisen with the padding during the decryption process of payload data within the Django registration view function

Struggling to find a solution for encoding my payload data before form submission. The plan is to have the view function in charge of registration decode the data, validate it, and then save it to the database. However, I keep encountering the following er ...

Discover the power of Vue.js 3 by seamlessly integrating anonymous functions within event handlers

Is it possible to invoke an anonymous function within an event handler in Vue.js 3? I came across several options on various websites: <button @click="return function() { console.log('test')}()">Click me</button> <butto ...

What is the best way to display a success notification when a transaction is successfully executed in web SQL

var brand = "Glare"; var price = "3000$"; var color = "blue"; var success = tx.executeSql("INSERT INTO truck (brand, price, color) VALUES ('"+brand+"','"+price+"','"+color+"' ")"); if(success) { alert("successfully insert ...

Utilizing a JQuery variable as an OFFSET parameter in an SQL query

Currently, I am working on incorporating infinite scroll functionality for posts within a news feed. The idea is for the posts to be dynamically loaded into the news feed when the user reaches the footer. The Challenge I am facing an issue with inc ...

JavaScript object containing the individual points of each person extracted using Regex form

Here is the string that I'm working with: Phantom_FR - 5 Points\n\nmineblox17,Dominus_Loading - 0 Points\n\ndavidroks528,beeks567,JohnDoe54631 - 4 Points\n\n\n\n **PLEASE ARCHIVE THIS CARD WHEN YOU ARE FINISHED ...

Master the art of sending multiple asynchronous requests simultaneously with suspense in Vue 3

Utilizing <Suspense>, I am handling multiple requests in my child component using the await keyword: await store.dispatch("product/getProduct", route.params.id).then(res => productData.value = res); await store.dispatch("product/get ...

Implementing Firebase with NextJS to append objects to a nested array

I'm currently working on my project using nextjs and firebase. The project concept revolves around a hybrid project management system where users can create projects with multiple boards to organize and store tasks: Board UI This is how I plan to sav ...

New data row successfully added to HTML table, revealing an object display

When I click a button, a dialog box opens up. I can fill out the form inside the dialog box and submit it to insert a row into a table. After submitting the form, the newly inserted row displays as [object Object] immediately after submission: https://i.s ...

Error Alert: UnhandledPromiseRejectionWarning in Async Series Causes Concern

I am currently working on a function in my project that uses the async series method to ensure specific tasks are executed in a certain order. In this case, function1 needs to be completed before function2, which must then be completed before function3. a ...

Tips for importing a JSON file from your local directory in Vue.js

I've been attempting to load data from a local JSON file in Vue. My goal is to simply load the data from the file and assign it to a variable. I'm not sure if I'm on the right track or if I'm missing something essential in my approach. ...