DEV Community

Discussion on: Optimize your JS code in 10 seconds

Collapse
 
elsyng profile image
Ellis

Agreeing with Eckehard. Optimisation and priorities are very very different in backend and in frontend. Backend and frontend are two very different beasts.

Collapse
 
efpage profile image
Eckehard

It is not only a question of priority. The reasons for a delay may be very different.

If an application needs to wait for some data, we can try to use some kind of cache if the result is used more than once. Or we can change the way in which data are requested. If you need to request a database scheme via SLQ before requesting the data, you get a lot of traffic forth and back, each causing an additional delay. If you run the same operation on your database server and ask only for the result, you will get the result much faster.

But If an operation takes the same time to finish a million of loops, you would probably need a very different strategy. In that case, optimizing your code might help, but it is probably better to find a strategy that does not require so much operations at all.

To know, if an optimization helps at all, it is necessary to know, what causes the delay. Without this knowledge, you can waste a lot of time optimizing things that are fast anyway.

Thread Thread
 
elsyng profile image
Ellis

In theory. But typically one shouldn't have a million of loops in frontend, that's backend's job normally. And that's my entire point. If one finds themselves having to optimise that kind of things on the frontend, then i think they should take a step back and re-evaluate, they've probably got their frontend/backend division wrong.

imho... me thinks ;o)

Thread Thread
 
efpage profile image
Eckehard

But things are shifting. There are a lot of SPA´s out there that just require some data and have no backend.

Thread Thread
 
elsyng profile image
Ellis

Aah, a lot of SPA's with a lot of data and million-loops, and no backend. I really know nothing about those, I don't even know an example case (feel free to share a url), but I'll take your word for it ;o)

Thread Thread
 
efpage profile image
Eckehard

See here, here, here, here, here, here, here or here.

This is from the vue-documentation:

Some applications require rich interactivity, deep session depth, and non-trivial stateful logic on the frontend. The best way to build such applications is to use an architecture where Vue not only controls the entire page, but also handles data updates and navigation without having to reload the page. This type of application is typically referred to as a Single-Page Application (SPA).

If you just have a database running on a server, I would not call this a "backend". React or Vue can run completely in the browser, so you just need a webserver and some API endpoints to get your data. An application like this would not run much faster, if you try to put the image processing on the server, but it´s worth to see, what causes the delay.

Thread Thread
 
elsyng profile image
Ellis

Thanks a lot, i will read👍

Thread Thread
 
mdledoux profile image
Martin Ledoux

dev.to/efpage/comment/2b22f

But things are shifting. There are a lot of SPA´s out there that just require some data and have no backend.

Realistically, they're getting the data from some backend somewhere, just not necessarily maintained by the maker of SPA. There are a lot of public APIs out there that can be consumed (which is how an SPA could have no backend but still huge data sets), and theoretically filters can be passed in requests to limit or prevent large data sets in the response.

Some comments have been hidden by the post's author - find out more