3

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 :

enter image description here

but the problem is , my app is very slow. There is a glitch in each section between opening the page and retrieving the data.

enter image description here

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)?

enter image description here

gauravmehla
  • 686
  • 6
  • 21
  • Did you get any chance check the performance of your service (at your backend) and it's rendering time? – David R Feb 06 '17 at 08:18

1 Answers1

5

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.

yibuyisheng
  • 149
  • 8
  • 1
    That's definitely it. TTFB is (most of the time) the time spent in the backend processing the request and preparing the data to send back. Maybe there's some slow query to a DB done there? – alebianco Feb 06 '17 at 08:30
  • https://gist.github.com/gauravmehla/46074bd14474c1edd6a7eff9b946119f I am making query to `mongodb` something like this.. is there anything wrong in that ? and also how to check query ? how to determine it is slow or fast ? @alebianco – gauravmehla Feb 06 '17 at 10:02
  • 1
    the _dumb_ way would be to put a couple `console.log` with the current time before executing the query and after sending the response. I don't know mongodb enough to try and give advice on the query and its performance. Plus that definitely requires a new question for the new problem – alebianco Feb 06 '17 at 10:20
  • This may help: http://stackoverflow.com/questions/25719782/mongodb-find-execution-time-for-count-command-on-millions-of-records-in-a-col @ alebianco – yibuyisheng Feb 06 '17 at 10:30
  • Yes you are right @alebianco. This is the output : `time => 216.479ms`. Query to mongodb took 216ms. :( do you have any idea how to solve this problem ? all of my queries are taking 210-299ms – gauravmehla Feb 06 '17 at 11:08
  • `time => 228.260ms, time => 238.354ms, time => 224.656ms` . I am using `console.time()` to calculate execution time. – gauravmehla Feb 06 '17 at 11:09
  • as i said, i don't know much of mongodb. post a new question for this specific problem and with the relevant tags, i'm sure someone can help with this ;) – alebianco Feb 06 '17 at 11:10