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?
2 Answers 2
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.
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.
Explore related questions
See similar questions with these tags.
/authentificate/...
Apche will redirect this request according to some rule to some application, java, php, python, whatever you have on backend.