Battle between Comet and Ajax polling

I'm looking to develop a chat similar to Facebook's chat feature.

Using Comet would require more memory to maintain the connection.

There seems to be a latency issue when using Ajax polling if requests are sent every 3-4 seconds.

Considering that latency isn't a major concern, would Ajax Polling be the better option in this scenario?

Answer №1

Aside from latency, another issue arises with using COMET (long-polling). This method "saves" your traffic by continuously checking for updates on the server. However, this means that some of the calls made could be unnecessary and a waste of resources, especially if there are no changes occurring. With COMET, only one call is generally needed to receive an update from the server with a 100% success rate.

Answer №2

@Vasil: "you can maintain millions of active connections"

Check out this issue

And regarding the misconception that NIO is superior to IO.

The article on iobound demonstrates that IO actually performs better than NIO and indeed, IO reaches its memory limit before NIO (incidentally, the author did not attempt to decrease the stack memory with a lower value).

Answer №3

In situations where latency is not a concern, AJAX may be the preferable option over Comet. Comet can face challenges when it comes to managing multiple connections between the same client and server unless handled with extreme caution. (Reference)

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

Ways to retrieve information from a different server utilizing AJAX

I am in need of fetching data from a file that is located at a different URL. Below is the code snippet that showcases the AJAX request being sent to the server. <script> alert('return sent'); $.ajax({ type: "POST", ...

After creating a new Packery using AngularJS, the getElementById function may return null

Alright, so I've got this HTML markup: <button ng-click="create()">create list</button> Every time I click it, I create a new list using the Packery jQuery plugin. app.directive('packery', ['$compile', function($com ...

Having difficulty accessing a PHP ajax post request

I've scoured every resource but can't seem to find a solution to this issue. I'm in the process of writing an ajax script, however, I am struggling to retrieve the correct value from the POST request. Here is the code I have so far: <t ...

I'm encountering an issue with the ajax_function that is displaying an error

Greetings to the Stackoverflow community! I am facing an issue while trying to utilize a script from your platform. I seem to be encountering an error regarding the ajax_function in my code. Can someone assist me in resolving or fixing this problem? Below ...

Getting an undefined error value in the ionic overlay side menu - what could be causing this issue?

My current challenge involves displaying the overlay side menu. I have written code to achieve this, adding a menu icon in the header that opens the overlay side menu when clicked, and closes it when clicked outside. However, I encountered an issue where ...

Maximizing Input Field Utility in React JS

I have a challenge with retrieving values from the input field and passing it to the useEffect. I specifically want the search to be triggered only after pressing the onSearch function. The issue is that I can only capture the value using the onChange func ...

The URL not functioning properly after including the .active class with JQuery

This website is built on the Shopify platform. To highlight an active link in a subcategory list, I am using JQuery and CSS to add the .active class to the element. However, after adding the JQuery code, the link element is not functioning properly and d ...

When transferring files to the src/pages directory in Next.js, the custom _app and _document components are not recognized

The documentation for Next.js mentions that the src/pages directory can be used as an alternative to /pages. However, I encountered a problem when moving my custom _app.tsx and _document.tsx files into the src folder, as they were being ignored. If you cr ...

The React Router's Switch component fails to update when the route is changed

In my component, I have a list of news categories. The links to these categories are in another component within the Router. However, when I change the link, the content does not update. I suspect this is because my NewsFeed component, where I define the S ...

Check the status of the audio source URL using JavaScript

I am currently live streaming audio to my player using the Soundcloud API. <audio></aidio> <source src="soundcloud-track-url"></source> Within my code, I have added an onerror eventListener for both the <audio> and <sourc ...

Utilizing React Typescript Discriminating Unions to choose between two different types based solely on props

In my project, I have a component that consists of different types: type Base = { color: string } type Button = { to: string } & Base type Link = { link: string linkNewTab: boolean } & Base type ComponentProps = Button | Link e ...

Angular Firebase Count of Items in List

My current dilemma revolves around obtaining a count of items within a firebase list. Firebase details: foods randompushid title: apple, comboQuery: apple23523526(userid) Angular Code snippet: this.foods= this.firebaseDB.list(& ...

Tips on leaving comments inside a render <div>

Hey there! I'm facing an unusual issue in my React+Webpack project. Even though I marked a line as a comment using //, it still gets rendered in the HTML output. Strangely, I have never encountered this problem before and can't figure out what tr ...

How can I show/hide a div based on checkbox click on my website? It works in jsFiddle, but not on my actual site. Any suggestions?

Is there a way to show or hide a div based on a checkbox click? I've got it working in jsFiddle, but for some reason, it's not functioning properly on my website. Any thoughts on how to fix this? My goal is to offer multiple payment methods (cre ...

What is the method to submit post data using jQuery or JavaScript?

I need help creating a button that can send post data to another location. Is there a way I can achieve this using JavaScript, or Ajax/jQuery? If there are any details missing from my request, please let me know. ...

Passing a JSON object as a parameter in a dynamically created element's click event using JavaScript/AngularJS

How to pass a JSON object as a parameter in the click event of a dynamically created element using JavaScript and AngularJS? var _dataObj = "{"sor_SourcingAgentId":1,"sor_Name":"xx"}" var _dynHtml= '<input type="button" ng-click="fnSelectcustom ...

Display a dynamic variable within React's HTML code

const fetchTime = () => { const currentDate = new Date(); const currentTime = currentDate + ' ' + currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds(); return {currentTime}; } export default fun ...

What is the method to execute jQuery code after the completion of a fade out effect?

I am attempting to fade out a div upon click while also adjusting some CSS properties. The problem I am encountering is that the CSS properties change during the fade out transition, instead of after it has completed. I would like the values to change onc ...

The Gatsby plugin image is encountering an error due to a property that it cannot read, specifically 'startsWith

While browsing the site, I couldn't find a solution to my issue, but I stumbled upon an open bug on Github. The only workaround mentioned at the moment is to utilize GatsbyImage. As I delve into converting a Gatsby project from version 2 to 3, I have ...

Using the fetch method to consume a RapidAPI JSON response

Currently, I am in the process of learning React Native and have initiated a project for that purpose. In this project, I have integrated RapidAPI (link: ) to fetch necessary data. Upon hitting the API, I receive a 200OK status, but unfortunately, I am fa ...