Ask HN: Good resource on writing web app with plain JavaScript/HTML/CSS?

185 points by pipeline_peak ↗ HN
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 ] thread
(comment deleted)
It depends on the thing you want to create. The browser UI controls are limited at best, keep your expectations low.

Writing 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.

Forgot to add

I want to make a simple app where users can create and fill out a form. ATC test plans, to be exact.

For something that simple you could check out PHP. Or even google forms, if you don’t mind something really simple and hosted by google.
> It's best to use some tooling

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.

I wish I could avoid web tooling, because I completely agree. But I’m forced to use it at work. Thankfully I’m free for my personal projects.
>Writing Vanilla JS is error-prone unless you are very disciplined

the absolute state of web developers in 2022

If you are trying to create a stateful web app it's true. Even with frameworks it can be difficult. I wouldn't want to write anything complex in vanilla JS.

You also lose a lot of niceties with DX, like TS and components.

Genuine question: what would you recommend using?

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?

what I'm saying you do need to know JS really well before you even touch frameworks
> Web app > Do I really need Node?

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.

Start here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fo...

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.

PHP. One file on a shared host for not too many headaches
You can definitely create and make a form, ala previous generation of web apps.

Sadly web components APIs are bizarre and unused by most web developers: https://dev.to/richharris/why-i-don-t-use-web-components-2ci...

You don't need web components to create a simple form.

Moreover, you really don't want web components for a simple form because even form participation is weird with web components.

>> You can definitely create and make a form, ala previous generation of web apps.

> 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.

> I am saying anything more complex than forms requires web component tech

No, it doesn't

Then please provide supporting arguments as I have done.
You did not provide arguments. You provided two statements: "You can build a form, but sadly web components are not popular" and "anything more complex than forms requires web component tech".

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)

OK let's look at how you communicated in this thread. Keep in mind I've been polite to you so far.

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.

> Implementing a web app without react or svelte would require using web components

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.

> No, web components are not required to build a web app

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 is saying that.

> 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 wrote:

> 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.

> Which is true, creating anything more complex than forms without a framework, as the OP mentions would require web component tech.

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.

> > Which is true, creating anything more complex than forms without a framework, as the OP mentions would require web component tech.

> 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.

(comment deleted)
I purposely wrote my home page (https://langworth.com) with plain, vanilla JavaScript, which features both WebGL and plaintext clients for a server-side text adventure game, because I wanted to remind myself that it's not that difficult to build something interactive and fun without miles of modern front-end tooling.

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

FYI uBlock's privacy filters block your script.js file for some reason.

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.

Thanks! I know that uBlock blocks the tracking script, but the rest of the site seems to work fine for me (also Chrome on Mac with uBlock Origin). If you have the time, could you check the dev tools console and email me with what you see?
I remember when Java EE came about. They had something called "Petstore Demo" running, and documented in articles. Isn't there anything like that for Node.js/js/html/css ?
You don't need framework. You can create classes, make api requests (axios), add 3rd party libraries in vanilla.

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.

If I were you, I'd use Node/express with server side rendered templates. It's pretty straightforward for a simple project that needs a backend.
Me and other contributors are writing and maintaining "Web app from scratch" scripts for popular frameworks here:

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.

Why using python3-django on debian instead of a venv and the last lts of django from pypi on your script[0] ?

[0]: https://github.com/no-gravity/web_app_from_scratch/blob/main...

How would you replace the line

    apt install -y python3-django
with "a venv and the last lts of django from pypi"?

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.

Like this:

    python3 -m venv .venv
    . .venv/bin/activate
    python3 -m pip install django
I think python packages should be installed through pypi, instead of being installed using whatever package manager your system use.
To me that is like way more convoluted than just using containers.
Can you elaborate on how "using containers" gives you a running Django instance?

Do you mean using a premade Docker image that comes with Django installed and configured?

You could have the environment ready and be ran on any container distro.. all they need to do is mount the files and go.
I was in the same boat with wanting to just learn plain HTML/CSS/JavaScript.

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.

I guess you will just end up writing your own framework in the end. There is a reason web framework exist - they all satisfy different needs in the domain of web development. Like routing, content update, state handling, event handling and so on. If you don’t need any of that, great, you can just learn and write plain html, css. So LMGTFY https://dev.to/jordanholtdev/how-to-create-a-web-page-with-h...

Cheers

> To me, the browser is the UI framework

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 :)

> 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.

Succinct description of the state of the web. Long will this continue.

For simple web "app" like form and form processing where you are not using dynamic reload of page elements, you can drop JavaScript and go with PHP + HTML + CSS. Use vanilla procedural PHP with sane splitting in functions / files. This stack is good enough for simple web apps, but also good for a little more complicated like for example task list etc. You can optionally sprinkle it with some vanilla JavaScript for dynamic parts, like showing disappearing error messages.
> you can drop JavaScript and go with PHP + HTML + CSS. Use vanilla procedural PHP with sane splitting in functions / files.

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.

I like to use Bootstrap for CSS, because I'm not a designer and I want a graceful experience on all devices. Plain JS can easily be thrown in there. You can also just use the default HTML form submission behavior. Bootstrap offers some helpful validation styles for client side form verification.

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.

I’ve also made use of cheap web templates based on bootstrap. For example, Inspinia and Color Admin.

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.

If you're coming from the WPF and winforms world IMHO you actually should find and use a framework. Find something that has a bunch of pre built components like cards, dialogs, buttons, etc. already styled and ready to go. You could go for something complex like react and a component library in its world, or go with something that is (mostly) CSS like bootstrap or bulma.

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.

Want to make browser-only webapps without node.js, bundling, building, transpiling and all that stuff?

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 recommend using Micronaut + Thymeleaf, its simple, easy and fast in both performance and developer productivity. Vanilla HTML, CSS and Javascript is fine. The best part by using Micronaut is that the documentation is really really good.

I do also think a single PHP file is maybe the easiest option.

You said app, which means you'll likely need some sort of backend. Express is pretty simple to get started with. These examples work out of the box and give you a simple starting point: https://expressjs.com/en/guide/routing.html

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

I don't know of a readymade resource except checking the usual places (W3Schools, MDN, LinkedIn Learning, Codecademy, Udemy, etc.), but just wanted to address some of your points...

> 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...

I fully agree with your sentiment. In case you need some tutoring, please don't hesitate to contact me here. I have 20+ years of experience in software engineering and webdev and I believe current state of web-development is completely screwed up.