L
L
lebedev1212019-04-25 16:34:16
Vue.js
lebedev121, 2019-04-25 16:34:16

Why is my REST SPA making too many http requests?

When visiting a certain page, my SPA, made according to the REST architecture, makes a separate http request for each individual entity (products, users, clients ... etc.). In general, according to the REST architecture, this is how it should be. What are some ways to reduce the number of requests to the server? I am not familiar, but I heard about SSR and GraphQL, maybe they will help somehow or if there are any other ways I would be grateful if you tell me. I wanted to make one request, and then everything would come from the server together.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Spirin, 2019-04-25
@lebedev121

For REST, you can return all the data associated with an entity or a collection of entities with a request:

{
  posts: [ ... ],
  linked: {
    users: { ... }.
    comments: { ... },
    tags: { ... },
  }
}

On the server side, you can stack data in window:
<script>
  window.__INITIAL_STATE__ = { ... };
</script>

A
Andrey Andreev, 2019-04-25
@b0nn1e

And what problems do you have with the number of requests?
What's the difference between a bunch of small parallel requests or one big one?

S
synapse_people, 2019-04-25
@synapse_people

Make 1 more endpoint that triggers others?
Those. some analogue of VK execute, which accepts method names, parameters and returns a general result, you can connect the JS engine to work out the result in the desired format

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question