Live data from Hacker News

Modern SPAs without bundlers, CDNs, or Node.js

kofi.sexy

31–40 of 170 posts

Re: Modern SPAs without bundlers, CDNs, or Node.js

#31
To go quite a bit off topic.

The author says that he starts with a single html file and splits it or incrementally adds stuff when needed.

That course of action has proven to be a really bad idea on every non trivial web project I worked on.

Mostly for teamwork and maintainability reasons.

E.g there is no clear project structure, the next dev will not understand stuff and do things differently. And welcome to the chaotic legacy code hell. It's like Php all over but in Js.

I usually work for customers who to some extend now what they want. I choose an appropriate tech stack for that use case. The team can use that stacks conventions to develop the project. There is no need to slowly grow, everything can be done in parallel and due to the conventions stuff sticks together in the end.

This sort of work flow has a tendency to just pile incredible amounts of code in files thousands of lines long. That is going to be unmaintainable in no time.

Everyone claims they don't do that but they all lie (yes you too).

Also everyone has a chance to end up maintaining the resulting amorphous blob (could be you again).

This lacks tooling like hot reload, spell checkers, linting and so on. You will need that anyway so why don't you start with it?

Also you need tooling for deployment like config files. Tests, Ci and what not...

Lack of documentation. Since this follows your personal style your colleague needs to follow. A framework provides documentation for that. Working like this, the docs need to be written by the devs. Although they may claim otherwise they usually don't.

Re: Modern SPAs without bundlers, CDNs, or Node.js

#32

I also sometimes enjoy this approach of starting from absolutely nothing. Instead of taking the path of starting with DOM manipulation and then going to a framework as necessary, I've kept really trying to make raw web components work, but kept finding that I wanted just a little bit more. I managed to get the more I wanted -- sensible template interpolation with event binding -- boiled down to a tag function in 481…

An even simpler bit of sugar over the DOM that I embed whenever I need just a little bit of JS: function $E(t,p,c) { const el=document.createElement(t) Object.assign(el,p) el.append(...c) return el } Usage: const button = $E('button', {onclick: () => alert('click!')}, [ $E('img', {src: '/assets/icon-lightbulb.png'}, []), 'Ding!', ]) (With thanks to 'goranmoomin: https://news.ycombinator.com/item?id=23590750 )

Oh, didn’t expect a reference to me at all, was thinking that the function was very similar to mine :)

That function is now in my must-haves in my new Django side projects; I usually overuse them before I finally move to a JSX-based UI library. It’s great for simple DOM manipulation… and for me it seems to create a semi-simple migration path in the case the code gets complex.

Re: Modern SPAs without bundlers, CDNs, or Node.js

#34

I think Vue.js is an excellent choice for this. They recommend bundlers and the default import doesn't come with the template compiler but the template compiler is fast enough to run when loading the page, and the vue template syntax looks clean inside a template string IMO, especially if you take care to minimize logic in templates.

view really deserves as serious a crack that react got, imo it's just better made. and vite is so good I think it's earned it.

I just don’t get the whole adding another DSL instead of using JSX or something.

Re: Modern SPAs without bundlers, CDNs, or Node.js

#35

I appreciate the principled avoidance of over-tooling and dependencies. importmap is neat! edit: In the same vein; cross-linking to "Writing JavaScript without a build system (jvns.ca)" https://news.ycombinator.com/item?id=34825676

Yeah, two really similar posts in a short time

Re: Modern SPAs without bundlers, CDNs, or Node.js

#36

What’s the benefit of the custom download-package script over npm install? Why would you want to roll a custom solution here?

Didn't get the idea as well. The end part of the post is like a seed for a future custom package manager or something

Re: Modern SPAs without bundlers, CDNs, or Node.js

#37
On the same topic, I wrote some articles a while ago. Here is my own approach for making a VanillaJS SPA without using any bundlers or frameworks https://rishav-sharan.com/#/making-a-spa-in-vanilla-js

Note that this blog right now converts markdown posts into html at runtime, which is definitely not an efficient way of doing things. But considering that I have just a handful of people landing there, I really haven't tried to update the approach.

Re: Modern SPAs without bundlers, CDNs, or Node.js

#38
post #28

I prefer to use vite - you get handling of imports without needing a separate bundler step, but you get hot reload as well. I find it is a nicer experience, YMMV but it is good to have alternative options: FROM node:19.1.0 WORKDIR /project/vite_project RUN npm init -y RUN npm install react react-dom RUN npm install -g esbuild RUN npm install vite EXPOSE 8081 CMD ["npm","run","dev"] The react install isn't normally th…

I agree, while it’s nice to go back to basics, I am more concerned with the end result, and vite works really nicely to achieve this. Any real project is going to use CI at some point so what’s the issue with having a build step in your pipeline?

Re: Modern SPAs without bundlers, CDNs, or Node.js

#39

To go quite a bit off topic. The author says that he starts with a single html file and splits it or incrementally adds stuff when needed. That course of action has proven to be a really bad idea on every non trivial web project I worked on. Mostly for teamwork and maintainability reasons. E.g there is no clear project structure, the next dev will not understand stuff and do things differently. And welcome to the cha…

As someone who does this too: it depends. If you take time out every now and then to completely refactor your code base it can actually be surprisingly effective. I've done exactly that on my last project and I'm pretty happy with the end result, you can have a look for yourself:

https://gitlab.com/jmattheij/pianojacq/-/tree/master/js

This project will likely never be finished, there are always nice new things to add or requests from people, there is no commercial pressure because it is a hobby project and I don't have a boss to answer to. And even if such refactoring operations take me two weeks or more (this one I did while I was mostly just working on a laptop without access to a keyboard so it was sometimes tricky to ensure that nothing broke) in the end it is worth it to me because I am also paying the price for maintaining the code and if it is messy then I would stop working on it. Project dependencies are the absolute minimum that I could get away with.

The project moves forward in fits and starts, sometimes I work on it for weeks on end and sometimes it is dormant for months. In a commercial setting or in a much larger team I don't think this approach would work.

Re: Modern SPAs without bundlers, CDNs, or Node.js

#40
While Safari doesn’t support importmap, it’s possible (and not too hard) to use them as a progressive enhancement so that it’ll still work, and safari users will get the benefit with 16.4. I did a writeup: https://qubyte.codes/blog/progressively-enhanced-caching-of-...
Post reply on HN