3

I have this application containing 2 parts:

  • User-facing SPA web served by Apache
  • NodeJS API server

When a user go to the SPA web, Apache will do authentication and prefetch data for that user by making a POST and a GET request to the API before serving the page. This works fine for normal days, but it is pretty slow when there is a lot of traffic.

Apart from improving the API, I think delegating authentication and data fetching to client-side would improve performance.

My questions are:

  • Does prefetch data by Apache before serving the SPA page hurt performance?
  • And would it be better to let client-side does the fetching?
  • 1
    Did you get any metric? Have you compared performances with other HTTP servers? Have you compared different approaches (without prefetching)? Are you sure the problem is the prefetching and it's not the SPA render? Or the server-side, due to heavy processes? As you see you first have to locate where the problem is in order to follow the proper strategy to solve it. Right now any question is going to be guesswork. You should first perform load test with different configurations to figure out where the problem is. Maybe you realise that NodeJS is not the best choice for certain web applications. – Laiv Mar 6 '18 at 17:05
  • I can not understand what do you mean by: Apache will do authentification and prefetch data? In most cases Apache just a layer between browser kind client and back end application. I would say it does nothing. What is your definition of Apache Do? What it usually does - it redirects request from outside to some process on your server. Apache itself should kind not do anything. So if the request Apache get is /authentificate/... Apche will redirect this request according to some rule to some application, java, php, python, whatever you have on backend. – Alex Mar 8 '18 at 20:30
3

I hate staring at busy spinners. The best SPA designs show the user SOMETHING while they load data in the background. Loading it from the client or the server isn't important at all to the user. The user want's to see something to know that your site is alive so they can stop hitting refresh. If that means showing them an incomplete load so be it. Just get something on the screen.

1

Without being sarcastic, you answered your question (partially) yourself:

Does prefetch data by Apache before serving a SPA site hurt performance?

but it is pretty slow when there is a lot of traffic.

But the problem is neither API as such, nor Apache nor client vs server side. The problem you are running into is a sign, that there is space for improvement in your design. If logging your users into your system is a problem, this should be factored out from the current backend into a separate backend part: be it a custom endpoint or a solution like keycloak.

And as CandiedOrange wrote: there is nothing more frustrating, than

staring at busy spinners

or looking at blank pages, because your SPA couldn't render the frontend because of missing information.

Read: Why performance matters

Perhaps you could improve your frontend with service workers and build a progressive web app.

But to give more than general advice "to improve", you have to tell us more details about the actual performance problems, you are having.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.