I am building a web application in which i have to make a lot of $http requests to server. i am using AngularJS in front-end and ExpressJS in back-end. i am making $http requests something like this :
but the problem is , my app is very slow. There is a glitch in each section between opening the page and retrieving the data.
Is the way i am making $http requests is architecturally correct or i am doing something wrong.
How to decrease Time To First Byte (TTFB)?
You should find out if the server is slow while handling the request by printing some log on server side.
I guess the problem is not on AngularJS, but the server side.
Related
I have a frontend-app, written in Vue.js, that displays data generated by a backend server. I would now like to run both, the frontend application and the backend server, on the same machine and make requests only locally, before providing the user with the information.
Currently, the requests are executed by the browser of each client, as the requests are made in the <script> tag of the Vue.js page source code. Is there any way I can implement it in a way that the frontend-app itself makes the requests, and not the clients?
Thanks!
My question is about:
I am currently trying to connect my electron application to my node server to get data from node.js server and print that data to my electron application. However I don't know how to do it. So could anyone help me:
To get data from node.js server into electron app?
The way you get data from any node.js server is you make a request to that server specifying in the request what you're asking for and the server responds with the appropriate data.
There are literally thousands of ways to physically make the request. The classic way in these days of web technologies is to make an http request from your electron app to an http server in your node.js server. You can make such a request from electron using the request() library.
You would then have an http server as part of your node.js server and you'd specify routes in that http server that handle the requests your electron client is making, fetch the desired data and send the data back as the response. In the node.js world, you can create a simple http server and a few request handlers in a dozen lines of code using the Express library.
This is the general approach. Further details on the exact request to make and URLs to use are dependent upon the details of what you're trying to do and the design you choose, none of which you've shared with us.
I just started learning AngularJS for my website development, and its perfect for what I need. However, I'm very new to web programming and I've been looking for the answer to my question for a while now, and I couldn't get a clear response. I'm wondering how I can handle incoming HTTP Requests in my AngularJS application.
For example, I'm going to have a computer running a program that is going to be constantly sending HTTP Post requests with data to the web server running my Angular app. I want to be able to parse the information in the app, and display the data using Angular's data binding. But, I can't figure out how in Angular you can listen for incoming HTTP requests, parse the data, and send back a response.
AngularJS is designed for front-end web apps. You use to make an HTTP request from the users web browser to a webserver listening for such calls. But angular itself can't listen for them.
If you want to be able to listen for a HTTP request you will want to try either apache/php or nodejs/express. nodejs will probably work best for you because you can program in javascript.
Is it bad to replace AJAX routes (called with $.Ajax from jquery) such as:
GET /animals
GET /animals/[id]
POST /animals
With socket.io events (event binded on client and server so the client can have a response):
emit("animals:read")
emit("animals:read", {id:asdasd})
emit("animals:write", animalData)
or should I "only" use socket.io it to push data to client?
[EDIT]
I could see one problem if I don't use socket io for my POST route. The problem is that I can't easely use the client's socket to broadcast data:
Server:
on("animals:write", function(data){
saveAnimal(req.data)
socket.broadcast(...)
emit("animals:write", writenAnimal)
})
VS
app.post(function(req,res){
saveAnimal(data)
// cant broadcast :(
res.send(201,writenAnimal)
})
I will push data to clients in some other requests for sure, so all clients will have at least 1 socket.
IMHO socket.io should be used if you want real-time data provided for your website. Take for example Stackoverflow. It uses websocket to update in realtime your scores and update your notifications.
But if you really want to create application that is SEO-friendly ( I mean supporting http for serving your pages ) and more important if you are aware of the difficulties in managing sessions and permissions in socket.io, I think you'll prefer AJAX for your pages and socket.io for other realtime data.
I would use ajax for this, its http based data requests, nothing realtime.
If you don't want to push data to the client, I don't see why you would use socket.io instead of AJAX. I mean with AJAX you don't need to handle a session with the client and it would probably scaled better.
With socket.io, for every connected client you need some sort of object on the server paired up with that one client. It will use more memory on the server for no reason if permanent connections are unnecessary or unwanted.
Also, AJAX will be better if you want to re-use your code with other systems, it is working with a huge existing ecosystem of tools.
That being said, if you need WebSocket features like pushing the data to the client or doing some kind of broadcast, you might consider using socket.io instead of AJAX since it will be hard to achieve this with AJAX and socket.io offers those features.
I developed one web application in which i am using AJAX polling to the server page i.e. servlet and getting the updated data after every 2-3 seconds ad its working fine, will 60-70 concurrent users pinging to the server for data affects the server load much? Will it make the server crash?
My Servlets are getting data from web service and I'm getting everything fine. But dont have much knowledge about the server load.
Please help me out.
Thanks,
Ars
For push channels I suggest you use
1) A designed library like http://socket.io/ which uses WebSockets and falls back to long polling
2) You do not use Apache which has not been designed to handle this kind of traffic, but use a web server which supports continuous streaming of events better. Eventually with Apache you will have scalability and other problems.