What's with web applications sending notifications via delaying loads? - ajax

I've noticed on a lot of applications recently, such as Google Docs and Facebook, that JavaScript is being used to load a file which doesn't load until the website needs to send you a notification.
Essentially, they're using an HTTP request to a file, and then the server which handles the file doesn't respond to the request (or may respond but not send the content) until the server wants to send a notification (such as a new IM or a document update) to the user.
I haven't been able to find much on the web about the best practices for doing this. It seems to be a relatively new technique.
I'm looking into doing this myself and would like to read more on it. Does this have a name? Are there established best practices for doing this?

You could start reading about Comet technology. And here is a good Comet Server, APE: Ajax Push Engine

Related

implement ajax push

This is a very general question. I intend to write a simple SNS which supports the client to send words(like twitters and facebook). Moreover, If there is a reply to someone's twitter, I want the web page to jump out a hint quickly. In this case, I do not want to use polling method. I search the internet and found that AJAX Push is a good way to implement that and I found that something Like APE or Comet. I use LAMP(apache server) architecture on my mac as a localhost. DO I need to change the server to a ajax push supported one? Or I can just implement ajax push on apache. I am really confused about that.

Ajax Server-Side synchronized HTTP request?

I am building a website which has a cron job that generates a file to the hard drive regularly. However, the timing of this generation is not precise and I would like it to be loaded as soon as it is generated by the browsers of my visitors.
Is there a nice way to make my server notify my visitor's browser to reload the page?
Other way around is quite heavy :(
Thanks!!
you should read about Comet, Comet allows you the receive "Push" from server-side to your client-side.
Eg,. thats the way how facebook chat works..
Take a look,
http://en.wikipedia.org/wiki/Comet_(programming)

Ajax vs. Web sockets vs. Web Workers

What is the difference between all three? They seem to do the exact same thing. Why and when would you choose to use one method over the other?
AJAX and websockets do similar tasks — they both establish a communication channel to a server. Web workers have nothing to do with either of them, they are just separate threads of JS execution.
AJAX is more mature than websockets — it has been around much longer and has a much wider browser support. AJAX is request-oriented — you make a request to the server, the server responds, and the connection is closed. Websockets on the other hand establish a persistent connection to the server, over which you exchange multiple messages in both directions.
Webworkers are useful if you want to perform a processor intensive task without blocking the browser interface.
They are not same. But one can use them together to build advanced application.
Ajax: As abbrevation States is asynchronous javascript and xml.. is used to load the content dynamically from the server upon called.
Websockets : Websockets is the feature defined in HTML5 . As wikipedia states "WebSocket is a protocol providing full-duplex communications channels over a single TCP connection." so this is mainly used for real time communication such as video call, live chat etc..
WebWorkers : this feature is also defined in HTML5. This is basically used to make bring multi threading feature in Javascript. Since javascript is a single threaded programming language , it breaks or pause whenever i.e heavy calculation tasks are done using it. to overcome this breakage , Webworkers are added to javascript.
You can perform Ajax and Websockets inside Webworkers . however you cannot manipulate DOM using webworkers due to security reasons.
They are not the same.
Ajax: It is a way of interacting with a web server asynchronously from a UI renderer
Web Sockets: An HTML5 feature using which you can interact with any Socket server extending the reach of the browser
Web Workers : Another HTML5 feature that helps you do multi-threaded programming from a web browser using Java Script
Ajax & Websockers are siblings.
Webworkers are completely different.
AJAX
The best example of AJAX is Google's search bar - suggestions appear as you type, but the current webpage is not redirected or refreshed! (10 years ago this was amazing, not so much anymore). This is AJAX in action.
AJAX uses what's called a "request" and "response" model: you ask a question, and you receive an answer from the 'server'.
AJAX allows webpages to talk to "servers" behind the scenes, allowing you to update a webpage without navigating away from your URL. Back in the old days of the web, if you wanted to show different content on a webpage, users would have to navigate to a different URL: not any more. This concept has been taken to the next level with single page apps and applications (like React, Vue, Elm etc.).
Websockets:
With websockets, your web-page talks to your server (as with Ajax), and your server responds - except you do so like you're talking on the phone. There is a "connection" between your users and your server. This "connection" is not there with AJAX: in that case, you have a simple request and a response coming back from the server.
In other words, if you wanted to stream stock market data, constantly updating it to your users: it would probably be better to use websockets, than AJAX.
Web-workers:
Use When you need intensive calculations - if you were to ask a web-page to calculate Pi to 100000 decimal places: that might take a while. The web-page might freeze, and you might lose $$. The intensive calculations can be done in the background, without freezing your webpage. People using your site can do other things - e.g. click around, while waiting for the result in the meantime.

Should I do API requests server side or client side?

I am trying to make a web app using ExpressJS and Coffeescript that pulls data from Amazon, LastFM, and Bing's web API's.
Users can request data such as the prices for a specific album from a specific band, upcoming concert times and locations for a band, etc... stuff like that.
My question is: should I make these API calls client-side using jQuery and getJSON or should they be server-side? I've done client-side requests; how would I even make an API call from the server side?
I just want to know what the best practice is, and also if someone could point me in the right direction for making server-side API requests, that would be very helpful.
Thanks!
There's are two key considerations for this question:
Do calls incur any data access? Are the results just going to be written to the screen?
How & where do you plan to handle errors? How do you handle throttling?
Item #2 is really important here because web services go down all of the time for a whole host of reasons. Your calls to Bing, Amazon & Last FM will fail probably 1% or 0.1% of the time (based on my experiences here).
To make requests users server-side JS you probably want to take a look at the Request package on NPM.
It's often good to abstract away your storage and dependent services to isolate changes and offer a consolidated and consistent web api for your application. But sometimes, if you have a good hypermedia web api (RESTful responses link to other resources), you could reference a resource link from another service in the response from your service (ex: SO request could reference gravatar image/resource of user). There's no one size fits all - it depends on whether you want to encapsulate the dependency or integrate with it.
It might be beneficial to make the web-api requests from your service exposed via expressjs as your own web-apis.
Making http web-api requests is easy from node. Here's another SO post covering that:
HTTP GET Request in Node.js Express
well, the way you describe it I think you may want to fetch data from amazon, lastfm and so on, process it with node, save it in your database and provide your own api.
you can use node's http.request() to fetch the data and build your own rest api with express.js

how to send some message to the users when now is looking my site's web page

how to send this messages to many people who looking my site on google app engine
1.using html5 ?
2.using ajax ?
thanks
Some technologies you can use for this include COMET (Ajax Push), Hidden IFrame (basically make the page never terminate and just send more data as it becomes available so the socket is never closed), html5 and websockets, or plain old fashioned XmlHttpRequest (some sort of polling mechanism as described by mirthlab).
You could set up an ajax poller to poll the server for the message and then display it.
Your question is a little unclear though. What will the message be used for. Does it have to show up without the user refreshing the page? Etc.

Resources