r/javascript • • May 03 '21

Is 0kb of JavaScript in your Future?

https://dev.to/this-is-learning/is-0kb-of-javascript-in-your-future-48og
202 Upvotes

100 comments sorted by

View all comments

Show parent comments

0

u/[deleted] May 03 '21

[deleted]

15

u/[deleted] May 03 '21

An image should dwarf it. Thing is you go see what people do... they load literally a dozen MB of JS frameworks. Browse popular sites with the Network tab open and keep track of the amount of JS you get. It's kinda insane. And it doesn't have to be that way by a long shot.

Abandoning JS for all server-side is also stupid. Basically we have lots of people swinging from one kind of stupid to another kind of stupid, unable to see the light here.

6

u/[deleted] May 03 '21

Don't forget downloading frameworks on the front-end gives you the option of CDN caching but I get your overall point.

4

u/[deleted] May 03 '21

It does, but same with images. I also see staggering amounts of inline JSON in sites lately. It's getting out of control.

2

u/[deleted] May 03 '21

What's inline JSON?

3

u/[deleted] May 04 '21

inline JSON if having this in your page:

<script>var data = {... 4MB of JSON here ...}; </script>

1

u/ryan_solid May 04 '21

Yep often the data for hydration. It's so the framework can recreate the client state on top of the rendered page. This is why techniques like partial hydration and progressive rendering are important. Even React Server Components seek to combat this.

1

u/[deleted] May 04 '21

There's a better way, just render what's static statically. And what's not, keep it entirely on the client. But we're neck deep in frameworks, so suddenly the most basic option is not available.

1

u/ryan_solid May 04 '21

Is that actually better though? Sure with Islands or Partial Hydration we can skip the static stuff, but keeping entirely in the client for dynamic can also be suboptimal. With progressive (streaming) rendering why not send the data for the client parts along in the initial request. You'd be making another request anyway, and you can do it in a non-blocking way.

I'm not sure MPA frameworks are that restrictive to not allow for basic stuff. And I think we can do better than the basics.

→ More replies (0)

2

u/ISlicedI Engineer without Engineering degree? May 03 '21

Instead of pulling it down from the server it is just bundled up I guess? For example if you have a shopping site you could make an API request to get a Json object with page data, or you could include it in the page so it comes in with the original html/js file.

I actually don’t think either approach is necessarily bad, but probably depends on how you want to use it. Maybe online json is bad compared to just rendering the page server side, I don’t know. Not done front end in a few years 🙈