r/javascript • • Sep 23 '19

You might not need a framework

https://medium.com/@pljeskavicica/you-might-not-need-a-framework-79444bda50d2
70 Upvotes

129 comments sorted by

View all comments

80

u/phpdevster Sep 23 '19

This seems like a fairly organized, but still jQuery-like approach without the cross-browser safety of jQuery. You're still doing manual DOM querying and state manipulating instead of something more declarative.

Gzipped and minified, Vue is just 20kb. It's so light weight that there's almost no reason not to use it for adding ad-hoc rich interactivity on a given page.

37

u/libertarianets Sep 23 '19

Might I introduce you to Preact?

40

u/zephyrtr Sep 23 '19

Preact is fabulous. I've used it a few times for simple sites. Now it even has Hooks, a CLI, and still loads in 120ms on a 2G network. And if shit gets really complicated, you can convert to a React app and keep all your code. It's quite nice.

Also React is not a framework, it' a library. People who go into React thinking it's gonna organize their code for them are gonna have a bad time.

7

u/-ftw Sep 23 '19

What is the drawback from using Preact over React?

12

u/dwighthouse Sep 23 '19

As I understand it, React normalizes the event system so it is consistent and all events work the same across all supported browsers (for example, certain browser events will not bubble, but React’s will). This synthetic event system, type checking, and now, their systems related to asynchronous rendering take up the bulk of the size of the library. If you only need simple click handlers, you don’t need these things. If you need to deal with very complex event handling, React can be helpful.

5

u/[deleted] Sep 23 '19 edited Sep 23 '19

You pretty much loose the eco system and all the bits and pieces that advance React, async rendering, cross platform and reconciling, fiber, suspense, etc. Some of these are ground breaking. Like dwighthouse said, React also normalized events, but this is not such a big deal any longer as pre evergreen browsers are dead, React will shed normalized events soon.

6

u/fuzzball007 Sep 23 '19 edited Sep 23 '19

How does it go in terms of dropping it onto a page with limited build tools? My use case would be something simple like displaying cards based on an ajax request, along with dropdowns/selects for tags/categories and pagination.

I've only learned React's basics, so for most of my projects which aren't large webapps I've been turned off from webpack's build process. Typically use gulp for all my stuff, how'd it go in a situation like this? Sounds appealing so far.

Edit: I'm usually building in PHP (WordPress) hence dropping onto a single page or two where's there's actual functionality to build. The stuff I've done using jQuery got messy quite quickly, even with using a fake state to store data before writing to the DOM

5

u/lifeeraser Sep 23 '19

I use Preact without build tools. (P)react is fully capable of running in a browser by itself with vanilla JS code. To use JSX, though, you need a transpiler, fall back to Hyperscript, or use something like htm.

→ More replies (2)

4

u/k4kshi Sep 23 '19

I started using Preact just yesterday for a small project and I'm amazed how good it is. So far I haven't hit any "oh come on, but react has it!" (I use v10 for hooks). And it's only 3.6k. Perfect for small projects

8

u/dwighthouse Sep 23 '19

Might I introduce you to hyperHTML?

No VDOM. Extremely fast. Requires no transpilation. 5KB.

5

u/grimr5 Sep 23 '19

Or lit-html and lit-element

3

u/dwighthouse Sep 23 '19

I prefer the original, but they do seem to be pretty fast.

→ More replies (3)

8

u/etca2z Sep 23 '19

Might I introduce you to Svelte r/sveltejs ?

17

u/[deleted] Sep 23 '19

Might I introduce you to server-rendered HTML?

6

u/FourtySevenLions Sep 23 '19 edited Sep 23 '19

Might I introduce you to Vanilla Javascript?

17

u/manoylo_vnc Sep 23 '19

Might I introduce you to my aunt?

9

u/FourtySevenLions Sep 23 '19

does she have cross browser support ;)

3

u/Sipredion Sep 23 '19

Happy Hogan has joined the conversation

→ More replies (1)

1

u/[deleted] Sep 24 '19

I was hoping someone would post about Svelte here. I have been having an amazing experience with it on my side projects.

3

u/unc4l1n Sep 23 '19

The parsed size is obviously much more, and on crappy mobiles it takes an age. Network is not the bottleneck for JS on mobile.

3

u/phpdevster Sep 23 '19

I've built plenty of sites and pages that use everything from a sprinkling of JS for form validation, to complex tables with client side search, sort, dynamic dropdown filters in the headers whose contents react to the results in the table, and custom cell rendering. They all work fine on my crappy iPhone 6, which is brought to it knees by all recipe sites and blogs and what not.

You will only run into issues on mobile if you're building big SPAs, but if you're building big SPAs without a framework, good luck to you.

1

u/unc4l1n Sep 23 '19

20KB gzipped is like 80KB to parse/compile. On an average mobile (not high end) that will take around 2s. This is not to be taken lightly.

1

u/volimsir Sep 23 '19

Vue is great :)

The point was just to showcase my opinion, on how easy it would be to have a basic component-based system with using basically nothing. I am definitely not advocating you do something like this if you need to build something complex. But for adding some interactivity to a small website, I don't see the harm.

Also, I don't believe cross-browser safety is really that much of an issue these days, as it was a few years ago.

1

u/phpdevster Sep 23 '19

Also, I don't believe cross-browser safety is really that much of an issue these days, as it was a few years ago.

Cries in IE11

→ More replies (1)

1

u/HiEv Sep 24 '19

Until very recently, it was still about 1 in 20 users in the US using Internet Explorer. Now it's about 1 in 50 (source). Personally, as much as I want to ignore IE, I'm not going to do that until the numbers get down to around 1 in 1,000 or better.

→ More replies (5)