News for hackers. Stuff that matters.
Re:Ask HN: Good resource on writing web app with plain JavaS... by alwillis on Thursday November 17, 2022 @02:50AM (#33636103)
Some of these responses… wow.

Using modern HTML and CSS will get you pretty far these days.

For example, dealing with forms used to be problematic in a few different ways without JavaScript or something server-side.

Now form validation can be done with CSS [1].

For example, static site hosts like Netlify have services for dealing with the form data [2]. 100 free form submissions per month.

I agree that tooling is out of control. Jekyll [3] is great for getting started with building static sites. When using Jekyll, my build tool of choice is a Makefile [4].

[1]: https://webkit.org/blog/13096/css-has-pseudo-class/#styling-...

[2]: https://www.netlify.com/products/forms/

[3]: https://jekyllrb.com/

[4]: https://blog.mads-hartmann.com/2016/08/20/make.html

Re:Ask HN: Good resource on writing web app with plain JavaS... by ZephyrBlu on Thursday November 17, 2022 @03:38AM (#33636364)
Netlify forms seems like the perfect product for OP.
Re:Ask HN: Good resource on writing web app with plain JavaS... by alwillis on Thursday November 17, 2022 @02:58AM (#33636146)
For layout/design, there’s open props [1].

I like the MDN for quick reference but the actual HTML spec is actually quite well written and has lots of useful examples [2].

[1]: https://open-props.style/

[2]: https://html.spec.whatwg.org/

Re:Ask HN: Good resource on writing web app with plain JavaS... by sdze on Thursday November 17, 2022 @03:58AM (#33636496)
Number 1 lags when scrolling on a 2018 MacBook Pro. Not a good advertisement of a product.
Re:Ask HN: Good resource on writing web app with plain JavaS... by shadeslayer_ on Thursday November 17, 2022 @04:02AM (#33636520)
Lags while scrolling on a 2021 MBP as well.
Re:Ask HN: Good resource on writing web app with plain JavaS... by aaaaarg on Thursday November 17, 2022 @05:09AM (#33636942)
hmmm it's good in my 12+ year old laptop in firefox.
Re:Ask HN: Good resource on writing web app with plain JavaS... by i_am_proteus on Thursday November 17, 2022 @05:19AM (#33637001)
Fine on a 2015 Thinkpad running Firefox on Fedora.

A product is poorly-advertised indeed, but which product?

Re:Ask HN: Good resource on writing web app with plain JavaS... by ExtremisAndy on Thursday November 17, 2022 @08:22AM (#33638471)
Yeah, I have to wonder if something else is going on with your machine/browser. Runs absolutely perfectly on my 2015 MacBook Pro.
Re:Ask HN: Good resource on writing web app with plain JavaS... by sdze on Thursday November 17, 2022 @06:34PM (#33647550)
I bet you don't use the Safari Browser. I checked again with Firefox on Mac and I didn't notice any performance issues.
Re:Ask HN: Good resource on writing web app with plain JavaS... by everythingabili on Thursday November 17, 2022 @01:18PM (#33643198)
[2] crashed Chrome 3 times. Mac Monterey.
Re:Ask HN: Good resource on writing web app with plain JavaS... by chrismorgan on Thursday November 17, 2022 @10:32PM (#33649763)
I don’t like Open Props on technical grounds: it’s pointlessly inefficient, largely an abuse of Custom Properties, to my mind, shipping a completely superfluous layer of indirection to every client, rather than flattening almost all of the properties at compile time as could and should be done. If you’re using something like Sass, you’d use variables for this sort of thing except where you do want to change values dynamically (e.g. different values in light/dark mode). Using Custom Properties for everything is just wasteful if you’re not going to have anything subsequently using the definitions themselves.

As an example, on their site, they’re sending about 68/12KB gzipped of styles. Some are already unused and could be removed by straightforward dead code removal. Inlining variables that are set only once and removing their definitions (which incidentally encompasses that dead code removal) reduces it to 40/8KB which will both transfer and evaluate faster. (A further 20% of the styles are also unused and possibly sanely removable.)

Re:Ask HN: Good resource on writing web app with plain JavaS... by zoover2020 on Thursday November 17, 2022 @02:56AM (#33636137)
For personal projects, sure. But good luck writing a medium to large sized app, full of business logic in Vanilla JS.

The hate for JS frameworks is usually warranted, in this case I think nuance is missing. It's also not as black and white as people paint it to be, IMO.

Re:Ask HN: Good resource on writing web app with plain JavaS... by atoav on Thursday November 17, 2022 @03:27AM (#33636297)
In the professional projects I have done the majority would have been possible to do with HTML/CSS/JS. The only reason not do that was that customers typically need some sort of backend and that was back then just simpler to do by other means.

But there is quite some projects where you don't even need that.

Learning HTML/CSS/JS is a good idea as ultimately any framework or serverside code will interact with some combination of the three. Having a strong grasp of how HTML/CSS/JS work is the perfect foundation for learning something that runs serverside. And you get there by building projects that predominantly lean on the three. Whether they are private or professional, who cares as long as they are cool and someone learns something from it?

Re:Ask HN: Good resource on writing web app with plain JavaS... by simion314 on Thursday November 17, 2022 @03:39AM (#33636366)
My problem is with "magic" frameworks.

For example angular hello worls is super duper simple. But then business apps become a giant pile of crap, the eprformance goes to shit and sometimes stuff that should work stops working. The issue is the magic, if use a sane library you can just run the code in debugger step by step and see what happens but with magic stuff you get a giant call stack with garbage that is impoosible to understand.

So when I can I rip out magic and replace it with function calls , getters and setters. Maybe is my bad luck that I always have to work on prtojects created by others and all the time this others did it wrong. Nobody can convince me that angularjs1 is a framework designed by competent people with experience in GUIs, maybe the newer version are better if those buys learned on the job what they should have known from the beginning.

Re:Ask HN: Good resource on writing web app with plain JavaS... by agentwiggles on Thursday November 17, 2022 @08:37AM (#33638637)
Do you feel React is overly magical? React was the first of these web frameworks that I was exposed to. I didn't have a ton of vanilla html/css/js experience when I first encountered React, but the fact that each component just returns some HTML is pretty unmagical to me. You could conceivably just use React (or, JSX really) to organize your app code in a pretty comprehensible way.

I guess once you get into all the hooks and contexts and fancier stuff things might start to be a bit magical. But I like it a lot better than Angular, which I agree is very much overly magicked.

Re:Ask HN: Good resource on writing web app with plain JavaS... by whostolemyhat on Thursday November 17, 2022 @05:20AM (#33637005)
> The hate for JS frameworks is usually warranted

It's almost never warranted.

Re:Ask HN: Good resource on writing web app with plain JavaS... by mcread on Thursday November 17, 2022 @08:27AM (#33638527)
So true, and hating JS is still a dogma that everyone has to assume ..
Re:Ask HN: Good resource on writing web app with plain JavaS... by brigandish on Thursday November 17, 2022 @09:17AM (#33639164)
You're suggesting that most of those that hate Javascript do so because someone told them they should and not because they've used it? From[1]:

> In 2008 Crockford published a book announcing his discovery that Javascript, contrary to prevailing opinion, has good parts. He describes this as "heresy", and as "possibly the first important discovery of the 21st century", noting that it came as a "great surprise to the community of javascript developers, and to the world at large." He attributes the discovery to his having read the ECMAScript Standard, which he says "literally changed my life." He also notes that the specification document is of "extremely poor quality", "hard to read", "hard to understand", and says that the ECMA and the TC39 committee "should be deeply embarrassed".

I own that book and I still hate Javascript (it's not the fault of the book). Is there another language with such a book?

[1] https://en.wikipedia.org/wiki/Douglas_crockford#Opinions_on_...

Re:Ask HN: Good resource on writing web app with plain JavaS... by achenet on Thursday November 17, 2022 @09:53AM (#33639638)
C++ I think gets similar hate.

Perl maybe, if you end up having to re-read some.

Re:Ask HN: Good resource on writing web app with plain JavaS... by brigandish on Thursday November 17, 2022 @06:15PM (#33647334)
I've definitely written Perl that someone has cursed at. Probably me!
Re:Ask HN: Good resource on writing web app with plain JavaS... by hutzlibu on Thursday November 17, 2022 @11:09AM (#33640940)
Well why do you hate javascript?

There are many languages that I do not like, but I hate none, so I am curious for the reasons of that strong feeling?

Re:Ask HN: Good resource on writing web app with plain JavaS... by skydhash on Thursday November 17, 2022 @12:10PM (#33642063)
No real standard library. You have the web API or the Node API to work with, and both are inconsistent.

The language is very permissive, making it not only easy to shoot yourself in the foot, but in the head as well. There is no easy way to say that your code is semantically correct because JS will allow it to digest anything. So, unless you do thorough review, bad code can easily get through.

Dependency hell if you're using NPM.

I'd be happy if the community was focusing on implementing some kind of default set of libraries, instead of adding syntactic sugar now and then on top of JS. I remember switching from Java to Kotlin, and the collection API was a real pleasure to work with. But in JS, everyone wants to use their set of libraries. Creating a starter project will get you hundreds of dependencies that you can never vet.

Re:Ask HN: Good resource on writing web app with plain JavaS... by hutzlibu on Friday November 18, 2022 @12:25AM (#33650727)
Well, I agree to most of the pain points, the ecosystem is a mess, due to history.

"The language is very permissive, making it not only easy to shoot yourself in the foot, but in the head as well. "

But I am actually not aware of much footguns of the language itself.

That is, if you stick with "the good parts" (even though I share not all the views from the book).

" Creating a starter project will get you hundreds of dependencies that you can never vet."

And it is possible to write clean vanilla js, or stick to limited frameworks. You have to maintain strict discipline though. And nowdays I would use typescript for a new project.

Re:Ask HN: Good resource on writing web app with plain JavaS... by brigandish on Friday November 18, 2022 @05:47AM (#33652914)
If we ignore all those pain points and ignore that we're sticking to "the good parts" and have to employ strict discipline and not rely on hundreds, if not thousands of unvetted dependencies and use typescript even though its type system has holes in it and nobody should mention the myriad build systems or varying APIs in browsers (its main target) or that its community can't come to an agreement on module formats/namespacing…

…and then I'll have no reason to dislike this language. Got it. Am I allowed to dislike the newish template literal syntax too?

Re:Ask HN: Good resource on writing web app with plain JavaS... by hutzlibu on Friday November 18, 2022 @05:56AM (#33652969)
You are of course free to dislike anything.

But you said "hate" before, which is a bit stronger than not liking.

The only time I came close to hating a language, was when I was forced to overtake someones half assed php project.

And I still do not like the syntax and have never touched any php code ever since, but I still do not hate the language, or its designers or users. I just avoided it. But hate has the vibe of wanting to destroy something ..

And well, yes, a nice clean start of the web would not be such a bad thing - if there would be some language or plattform everyone can agree on. Which is likely not happen and will just recreate the mess we have already.

Re:Ask HN: Good resource on writing web app with plain JavaS... by brigandish on Friday November 18, 2022 @07:26PM (#33665089)
There are degrees of hate. If we're talking about programming languages, then I hate JS, while there are languages I love. Who likes the experience of writing in Bash, for instance? It's ugly, limited, and has a series of gotchas, which is much like JS.

> hate has the vibe of wanting to destroy something

You may be right, and given half a chance…

Re:Ask HN: Good resource on writing web app with plain JavaS... by austin-cheney on Thursday November 17, 2022 @08:32AM (#33638573)
Done: https://github.com/prettydiff/share-file-systems

The hate for large frameworks is warranted by their poor performance and bloat while struggling to achieve simple objectives in the most challenging ways.

Re:Ask HN: Good resource on writing web app with plain JavaS... by staz on Thursday November 17, 2022 @04:19AM (#33636632)
`has()` for form validation really looked interesting but then I saw on their first example in your link that it is not supported in Firefox https://caniuse.com/css-has
Re:Ask HN: Good resource on writing web app with plain JavaS... by TeMPOraL on Thursday November 17, 2022 @05:08AM (#33636932)
I dream that one of these days, CSS will get a selector similar to `has()`, but that can target text content, not the structure. E.g. I want to be able to write something like:

  article a :has_("click here ")
to select elements that are otherwise hard or impossible to target. Of course, I don't want to use it on the websites - I want it for userstyles, so I can swiftly and efficiently deal with the insanely bad UX of most of webpages, despite their authors making it hard to fix (often on purpose).

That, and I'd like some way to punch through shadow DOM, because as far as I can tell, elements in the shadow DOM cannot be addressed by userstyles at all, which prevents me from fixing annoyances in some webapps (looking at you, Gerrit).

Re:Ask HN: Good resource on writing web app with plain JavaS... by informalo on Thursday November 17, 2022 @07:20AM (#33637924)
For userstyles, you can do that with uBlock's custom filters [1] [2]

  news.ycombinator.com##a:has-text(Hacker News):style(color: green !important)
[1]: https://github.com/gorhill/uBlock/wiki/Procedural-cosmetic-f... [2]: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#...
Re:Ask HN: Good resource on writing web app with plain JavaS... by notpushkin on Thursday November 17, 2022 @08:19AM (#33638434)
The only problem with that is that uBO applies it via JS polling (I think?) and this results in the unstyled content flashing very briefly. Pretty annoying sometimes; hope it also gets into a standard (or jyst gets a native implementation for the sake of adblocking).
Re:Ask HN: Good resource on writing web app with plain JavaS... by zzo38computer on Thursday November 17, 2022 @04:27PM (#33645995)
My idea of a web browser design is some CSS commands which are only available for user styles, including these features (text content, shadow DOM, etc; although, such things might also be useful even if not restricted to user styles) and some others, such as more control over priority, and overriding the meaning of other CSS commands (which are restricted to only being allowed in user styles).
Re:Ask HN: Good resource on writing web app with plain JavaS... by chrismorgan on Thursday November 17, 2022 @09:51PM (#33649348)
In some contexts, which includes JavaScript and thus user styles, you can use XPath, which interacts with all nodes, not just element nodes like CSS. Your sample selector would be this, if I have understood your intention correctly¹ (that you’re targeting the <a> element, and don’t care if the text “click here ” is an immediate child, or spread across multiple children):

  //article//a[contains(., "click here ")]
The equivalent to document.querySelector in JavaScript:

  document.evaluate(
    '//article//a[contains(., "click here ")]',
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null,
  ).singleNodeValue
And the document.querySelectorAll (which returns a static node list) equivalent would use ORDERED_NODE_SNAPSHOT_TYPE, with .snapshotLength and .snapshotItem(index) on the result object. Yes, this API is written in a very old style, and could do with being wrapped in a more pleasant API.

See https://www.w3.org/TR/1999/REC-xpath-19991116/ for the syntax, and https://developer.mozilla.org/en-US/docs/Web/API/Document/ev... for document.evaluate(). You will sadly not find a great deal of other useful documentation.

As for shadow DOM: yeah, you can’t target closed shadow DOMs at all in any way, by design. Fortunately most are open so that it is at least possible to get into them, even if it’s a pain since the normal tools can’t pierce the boundary.

—⁂—

¹ If you wanted to only match “click here ” in an immediate child text node of the <a> element, these four work and are equivalent:

  //article//a[./text()[contains(., "click here ")]]
  //article//a[text()[contains(., "click here ")]]
  //article//a[contains(./text(), "click here ")]
  //article//a[contains(text(), "click here ")]
These will be more efficient than the first-used selector. Where CSS is mostly unaffected by selector complexity because it largely evaluates from right to left, XPath is more likely to be doing full traversals, which will benefit from more specific selectors, hence things like prefixing paths with /html/body, or only evaluating in document.body, in order to skip traversing the head altogether, if that will never match; and you can easily imagine that contains(//a/text(), "…"), which selects text nodes that are children of <a> elements and thus has selected nodes that have a trivial string-value, will be faster than contains(//a, "…"), which will need to stringify every <a> element, entailing further traversal and string construction. Mind you, the differences in all this will mostly be very small in practical terms.
Re:Ask HN: Good resource on writing web app with plain JavaS... by alwillis on Thursday November 17, 2022 @08:06AM (#33638329)
It’s behind a flag in Firefox; should be on by default “soon”.
Re:Ask HN: Good resource on writing web app with plain JavaS... by alwillis on Thursday November 17, 2022 @07:54PM (#33648310)
Even without Firefox support, :has() is supported by about 83% of web users, which is pretty good considering it first shipped 8 months ago.
Re:Ask HN: Good resource on writing web app with plain JavaS... by cxr on Thursday November 17, 2022 @07:40AM (#33638067)
> Some of these responses… wow.

It's pretty amazing, HNers' capacity to read a request that includes a clear, concise (and satisfiable) requirement—no frameworks—and then dozens of respondents write up answers predicated on the use of this or that framework, thus contradicting the entire premise for the question.

Re:Ask HN: Good resource on writing web app with plain JavaS... by alwillis on Thursday November 17, 2022 @08:06AM (#33638332)
Exactly.
Re:Ask HN: Good resource on writing web app with plain JavaS... by pipeline_peak on Thursday November 17, 2022 @11:24AM (#33641185)
People just love to talk about their favorite shit... They have the right to post it, but I also have the right to ignore their suggestions
Re:Ask HN: Good resource on writing web app with plain JavaS... by aussiesnack on Thursday November 17, 2022 @03:46PM (#33645411)
It can be pretty tiresome and there are some topics I just never bother reading because they are inevitably full of humanbot autoresponses. Anything to do with note or mail apps, for example, will be just packed with readers taking their own particular dog for a walk, regardless of its relevance to the topic at hand. Pub bores, the lot of them.
Re:Ask HN: Good resource on writing web app with plain JavaS... by _boffin_ on Thursday November 17, 2022 @10:23AM (#33640130)
agreed. it's amazing. Actually just wrote a site a few days back only using HTML, CSS. It's a simple site, but still looks good with only a few hundred lines of CSS. peeps are nuts for thinking that you need javascript and bells and whistles.

I did miss SCSS though.