DEV Community

Cover image for What are the pros and cons of StimulusJS and AlpineJS?
Andrew Stuntz
Andrew Stuntz

Posted on

What are the pros and cons of StimulusJS and AlpineJS?

I've been using StimulusJS heavily on two rails apps I have been working on and honestly, I'm loving it. But, I have been reading and hearing a lot lately about AlpineJS. What are the pros and cons? Should I be using AlpineJS instead of StimulusJS?

Top comments (4)

Collapse
 
bizzibody profile image
Ian bradbury

This is a great topic.

I needed some page/server interaction so I investigated Stimulus. I watched a few videos etc and thought - okay - let's do this. I did complete the feature(s) but I was never comfortable.

Then I started using Tailwinds and came across AlpineJS. I'd never heard of it before so I watched a few videos etc etc and it was like a eureka moment.

I realised I was not happy with how Stimulus integrates into a project. It makes backend changes that I just don't understand - like a big black box in my code. And it's definitely all or nothing.

AlpineJS however is super light and all in the client. Sure you loose the direct model/controller integration but isn't that what json api calls are for? I've found it extremely easy to work with and have yet to find a feature I can not deliver.

I have one last Stimulus feature to remove. When I get the time - that will be refactored to AlpineJS and then I'm done with Stimulus.

Collapse
 
leastbad profile image
leastbad

Stimulus is a 100% front-end technology. You could run it off a CDN if you wished to.

Honestly, I just don't believe that you've done a lot with Stimulus because what you're saying just doesn't make any sense. Is it possible that you didn't use it properly?

Collapse
 
drews256 profile image
Andrew Stuntz

Interesting. What are the backend changes that are happening??

Collapse
 
bizzibody profile image
Ian bradbury

I'd say mainly in the use of a Gem and changing the location of code, stimulus code lives in it's own directory off of the Javascript directory. I really like that you add AlpineJS inline with your html - it makes for super readable code. With Stimulus I have to go hunting.

I'm ignoring the need for Yarn and Webpack as I have grown comfortable with these technologies, especially as they do seem to work. I know that I could use CDN's but I'd rather be in control and know exactly what is being served to users.