Ask HN: Good resource on writing web app with plain JavaScript/HTML/CSS?
Coming from WPF and Winform, I find web development to be unnecessarily complex, but I refuse to believe that’s true.
I just want to make a simple web app, no React, Angular or any of that. That can’t be too hard right? I’m sure in large scale, that stuff has its place, but I don’t need it. To me, the browser is the UI framework.
When I Google around to get started, I find obnoxious Medium articles. I don’t want to copy and paste instructions and throw something together without a clue what’s going on. Mozilla has good documentation, but I don’t know what’s a good source to actually get a web app running locally that I can eventually deploy online. Do I really need Node? Compared to WPF/Winform this is a mess, or so I hope not.
I want to make a simple app where users can create and fill out a form. ATC test plans, to be exact.
198 comments
[ 0.25 ms ] story [ 168 ms ] threadWriting Vanilla JS is error-prone unless you are very disciplined, writing "Vanilla" CSS is OK for the most part, Vanilla HTML is fine. It's best to use some tooling, but there are dozens to choose from.
I want to make a simple app where users can create and fill out a form. ATC test plans, to be exact.
Please don't hurt OP. They're new to this and want help.
They should avoid web tooling forever if they want to maintain their sanity. It's just a mess of a hundred and one tools that all do half of what every other one does, built by people who just refuse to get along and standardise on the Best Way ™ to do things.
the absolute state of web developers in 2022
You also lose a lot of niceties with DX, like TS and components.
Both companies I worked for in the early 2010's ended up recreating their own (subpar) implementations of what React does.
While I do agree the bar to get started on the web is too high, I feel like it's never been so low?
React and frameworks like Next.js have been great to use. Much better than what I was using back then.
I don't have experience with e.g. Laravel/Ruby on Rails though. Are these any easier to work with?
Do you need a back-end? If so, doesn't need to be written in JS.
React / Angular are for SPAs- single page web apps- load once and you've got the entire client.
No reason it needs to be this way. Just serve the page from the back-end.
Also perfectly fine for it to be an SPA. You can use React, which has some nice features for managing the page lifecycle.
Preact is a much lighter weight React.
Svelte and htmx are both nice alternatives.
Once you throw a few input elements and a submit button into an html file, you can use the network tab in your browser's "Web Developer Tools" or "Inspector" to see how the form submission looks over the network.
You will need some kind of stack on the server to interpret the submission and do something, like stash it in a database or maybe in your case just append a string to a file. I like Node and use nothing but its built-ins for creating servers and writing to my filesystem.
Speaking of built-ins, python and php can be good too, they can create and interface with sqlite databases out of the box.
So I don't have an exact direction to point you but feel for you re: crap medium articles. I found it worth paying $25 to https://teamtreehouse.com/ to choose from the many tutorials there, lots of intro content of good quality.
Sadly web components APIs are bizarre and unused by most web developers: https://dev.to/richharris/why-i-don-t-use-web-components-2ci...
Moreover, you really don't want web components for a simple form because even form participation is weird with web components.
> You don't need web components to create a simple form.
Yes, we agree. I am saying anything more complex than forms requires web component tech that isn't popular or liked by developers.
No, it doesn't
You can go to State of JS and see the top used frameworks https://2021.stateofjs.com/en-US/libraries/front-end-framewo... You can then tell me how many of them "require web component tech" (hint: only lit uses web components as underlying tech, none of the others use those, and have no intention to)
1. > You did not provide arguments.
Yes I did. I wrote:
> > Sadly web components APIs are bizarre and unused by most web developers: https://dev.to/richharris/why-i-don-t-use-web-components-2ci...
> > I am saying anything more complex than forms requires web component tech that isn't popular or liked by developers.
You obviously know these are supporting arguments, because they seek to back up the statement that 'more complex apps are harder to build without frameworks'. This is high school level logic, so I will presume that rather than being unaware of what a supporting argument is, you're just being deliberately antagonistic.
2.
> No, it doesn't (end of post)
You misread me (see next point) and rather than responding with content (which would have cleared this up earlier) simply disagreed without supporting arguments.
3. You misread me. I wrote:
> I am saying anything more complex than forms requires web component tech that isn't popular or liked by developers.
Judging by your comment about frameworks not using web components (which you'd know I'm aware of, given that I posted an article by the author of Svelte about why Svelte doesn't use web components), you think I’m discussing implementing a new framework. Nobody is discussing that. The OP is making a web app, not a new framework.
Implementing a web app without react or svelte would require using web components which is, as mentioned, a set of poor and unused APIs.
Given 1, 2 and 3, it's obvious that you're being clearly antagonistic to someone that has been polite to you thus far, I will change how I communicate - Dmitri, you're a cunt. Sorry Dan.
You keep stating this as a fact with literally zero supporting arguments.
No, web components are not required to build a web app. Web's largest and most successful web apps and web sites have been built before web components even became a thing and keep being built without using them.
> I will change how I communicate -
You are not communicating. You're presenting your personal opinions as facts.
Nobody is saying that.
Nobody has ever said that.
I have explicitly said the opposite since https://news.ycombinator.com/item?id=33635218.
You are arguing with yourself.
> Nobody has ever said that.
nailer, 1 day ago:
"I am saying anything more complex than forms requires web component tech"
https://news.ycombinator.com/item?id=33638793
---
nailer, 7 hours ago
"Implementing a web app without react or svelte would require using web components"
https://news.ycombinator.com/item?id=33652391
---
Edit. It's also funny/sad that you say "nobody is saying that" to my comment which quotes the exact part were you're saying that.
> I am saying anything more complex than forms requires web component tech
> Implementing a web app without react or svelte would require using web components
Which is true, creating anything more complex than forms *without a framework, as the OP mentions* would require web component tech.
You wrote:
> No, web components are not required to build a web app
What I wrote is not the same thing as saying "web components are required to build a web app".
Occam's razor: I suspect you genuinely made a mistake, and may speak English as a second language, but also are very young or not well developed, so rather than admit the error you're trying to argue with me about something I never stated.
For the third time you present this opinion as undeniable fact, when it is not true in any way, shape, or form.
> What I wrote is not the same thing as saying "web components are required to build a web app".
You literally just said that.
> I suspect you genuinely made a mistake, and may speak English as a second language, but also are very young or not well developed,
Ah yes. First it was calling me a cunt. Now it's ad hominem attacks.
> so rather than admit the error you're trying to argue with me about something I never stated.
Literally, again and again, you insist that complex app require web components (the question of frameworks is entirely irrelevant). When I answer that no, they are not required, you are pretending you provide arguments, calling me a cunt, or calling me "not well developed".
Again:
Even if you build stuff without frameworks, web components are not required. To see proof that they are not required it's enough to look at literally tens of thousands of complex web sites built without them before they ever existed, or since. Yes, tens of thousands of complex sites that were built (and are being built) without web components or web frameworks.
Moreover, the only reason those web frameworks exist is that people reached a certain level of complexity, and packaged that complexity in a single generic solution, and still they don't require web components.
But sure, do go on stating your bullshit opinion as fact with zero supporting arguments while calling people cunts. This will show the world how well developed you are.
> For the third time you present this opinion as undeniable fact, when it is not true in any way, shape, or form.
It's the majority opinion of the web dev world. We ll use components, moving from using React / Svelte / Vue etc to W3C web components is tough, and moving a world without components at all would be very, very difficult.
The existence of some great backbone.js or GWT web app written in 2005 doesn't prove that statement to be incorrect.
If you think it does, say why, but not to me, I'm tuning out. Bye.
https://chrome.google.com/webstore/detail/hn-blocklist/cgphk...
PS. I tried being polite while you did 1, 2 and 3 https://news.ycombinator.com/item?id=33652391. You have zero right to complain about how I conducted myself towards you.
It started as a single page but I eventually broke it out into a few files for organization. The WebGL parts are lengthy and boilerplate-y because, well, that's GL for you. https://github.com/statico/langterm
Even after disabling it, though, it's just a blank screen (Chrome on Mac).
Clicking "Use text mode" does work though and brings you to a console.
The only thing you have to watch out for if you are making a public app (but I think you are doing internal) is security- in vanilla you must implement protection yourself (xss, content secuirity policy etc.) and most modern frameworks already either implement that or make it easier to do.
https://github.com/no-gravity/web_app_from_scratch
The idea is to have a self-explanatory shell script for each framework, which turns a fresh Debian installation into a running web application with routing, templates and user accounts.
So far, we have Django, Flask, Laravel and Symfony. In various stages.
If you look into the scripts, you see that they are pretty much tutorials in code form. Reading one of them shouldn't take more than 10 minutes. After that, you know exactly what your web app does.
[0]: https://github.com/no-gravity/web_app_from_scratch/blob/main...
I would be curious to see which lines you replace this with and if the script runs the same afterwards.
Personally, I run an application either in a container or in a VM. So I never had the need for virtual environments. Does the latest Django version give you something you are looking for that is not in Debian's version?
A benefit of doing it the Debian way is that it is easy (one line of code) and no extra system has to be put in place for updates. As Django is updated along with your OS updates.
Do you mean using a premade Docker image that comes with Django installed and configured?
Mozilla docs didn't quite do it for me but I swear by W3SCHOOLS website.
I also found this guy's website helpful: https://gomakethings.com/
I think the author is on HN; he swears by plain JS.
For me I just wanted to write a simple cross platform app, I decided Dart/Flutter was the way to go in the end.
Cheers
It's not. It's a haphazard collection of hacks and one-off solutions that first grew organically, then not at all, then got taken over by bizarre corporate interests.
> I don’t know what’s a good source to actually get a web app running locally that I can eventually deploy online.
You need the backend part for this that handles for submission. For the frontend you need a static web page with just HTML and CSS.
So I would stop looking at JS to keep your sanity, and look at a simple PHP or Python or Ruby framework/lib that will give you the scaffolding to handle form submissions and templating to create an HTML page. Like Sinatra.
Since you already do .net I presume, you can go ahead and do that in ASP.net :)
Succinct description of the state of the web. Long will this continue.
I like this approach for simple websites, and it can be a very useful learning exercise, but I don't think this is enough to find a job later.
Unfortunately, to remove CSS bloat from your completed Bootstrap template you need to use a node based script. Check "Purge CSS", although there is another one.
No need to get into bloated SPA frameworks or JS on the backend. From my side JS is just a necessary evil for webdev. Prefer to keep it in the browser where it is required. For the backend, choose a sane language you are comfortable with.
Using a WASM blob + canvas/WebGL as a client is another option which is increasingly appealing. You still need some JS glue, but you're free from some of the browser madness. Depending on how you build your client, you maybe able to recycle it into a standalone binary.
You can go quite far with these, and you don’t even have to strip out all the unused dependencies if you don’t want to.
The included minified bundles will deliver a ton of different swiftly common UI behavior, with super light config, (sometimes just the right html).
As parent said, you can easily add your own custom JS for any given page.
If you want to go deeper into modern JS, such as organizing your code into modules or making use of your own chosen node modules—-forgo toolchains and just use esbuild. It’s great.
I say this because where you're coming from you're used to plopping down a dialog and throwing components like forms and buttons and such on it. With plain HTML and CSS it is much, much more free form and you can easily be paralyzed by choice or indecision with how to design or even just how to layout components. With a framework like bootstrap you're given layout primitives like a grid and higher level components like a navigation bar, menus, etc. which are much closer to what you're used to from C# and windows.
This experimental view library might interest you: https://github.com/jehna/longwood
It's usable with plain in-browser Javascript, no other tools needed. You can split your frontend to components and do conditional rendering logic just as with any templating library.
I do also think a single PHP file is maybe the easiest option.
Then you can layer on HTML, frontend JS, and CSS. With modern typescript you can definitely write pure JS and be "fine".
That said, after a while once you grok how it all works, I would try React.
> Do I really need Node?
As an alternative, you could look at using a vercel template with some sort of out-of-the-box cloud database. These are super simple to get started, although they go against your goal of not using frameworks for the most part. https://vercel.com/templates
> Coming from WPF and Winform, I find web development to be unnecessarily complex
The web is actually quite a bit lower-level than that, sadly. Winforms (at least when I last used it in the late 90s...) was actually really nice in comparison, especially when you use it with Visual Studio. Web has nothing quite like the built-in GUI editor in VS, except maybe something like Adobe Dreamweaver -- which is an approximation of a browser's renderer, not an actual pixel-perfect layout engine.
If you're looking to "compose" a web app out of UI widgets -- dropdowns, buttons, menus, etc. -- you might want to consider going one level of abstraction higher and using something like Bootstrap or UIKit or SemanticUI. These are NOT Javascript-extending frameworks the way React or Angular are, they're just collections of very useful UI primitives with sane defaults. You can typically use these just by dropping in a couple <script> and <link rel="stylesheet"> tags (meaning you're staying well within "vanilla" HTML/CSS/JS).
> a simple web app, no React, Angular or any of that. That can’t be too hard right? I’m sure in large scale, that stuff has its place, but I don’t need it.
Actually even for a small app, the right framework can make it quite a bit simpler than vanilla JS. But I won't preach here since you're specifically not interested.
> To me, the browser is the UI framework.
It's not though =/ HTML by itself isn't very useful; it doesn't do interactive things at all without either Javascript or some sort of backend that you POST to. CSS lets you have hover states and dropdowns but it's still not real interactivity.
So you have to choose... do clientside logic (entirely doable in vanilla JS, just tedious as heck and error-prone) or offload it to a backend server of your choice (using whatever language or framework you want; there are many).
> I don’t know what’s a good source to actually get a web app running locally that I can eventually deploy online.
Over the last ten years or so, we've gone from "deploying" web apps to actually needing to "build" them first, kinda like compilation/transpilation + bundling + tree-shaking (size optimization) all in one. But by and large you shouldn't need to do that (have a buildchain) if you're writing vanilla HTML + JS + CSS. That usually just leaves you with a bunch of files that the browser runs directly.
To run them locally, you can spin up a simple web server (something like Apache or Nginx, with or without Docker or Lando or other such containerization services) or if it's really simple enough, just open the file directly in your browser.
To host them online, you just have to upload them anywhere -- the old ways of SFTP still work, or these days there might be Git-based plain HTML hosts (I'm not sure; it's not so common a need). If you're feeling lost as to where to host your files, check out Nearlyfreespeech.net, Google App Engine, Cloudways, Hetzner, DigitalOceans, etc. You can always manage your own S3 instances too and deal with CDNs and DDoS etc. on your own, but why...? No need to reinvent that wheel.
> Do I really need Node?
No. Node is a server-side/backend runtime for Javascript. It replaces things like PHP or Ruby or Java on the backend. If you're making a vanilla JS web app for browsers, you do NOT need Node... unless you are deliberately choosing to make your backend in Javascript too!
The reason Node is sometimes used for frontend web frameworks is just that it keeps the ecosystem in one language, so the frameworks themselves and build tools and developer tools etc. often depend on note. But once the web app is built, it is deployed to the web as regular file...