5 ms·
You might not need JavaScript
- transfire 4y agoInformative. Thank you.
- behnamoh 4y ago> http://youmightnotneedjs.com/#form_validation http://youmightnotneedjs.com/#form_validation Interesting, but how is "form validation" through HTML, SCSS not a security threat? I mean, you basically tell attackers how to brute force. I do wish more websites would use these techniques where appropriate to make the web faster, but maybe using JS is good to keep web developers employed (imagine if so much of demand were implementable via markup languages, reminds me of this post: http://harmful.cat-v.org/software/c++/I_did_it_for_you_all http://harmful.cat-v.org/software/c++/I_did_it_for_you_all).
- Blahah 4y agoFrontend form validation is not for security, it's for user experience. Backend validation is for security.
- usr1106 4y agoA lot of form validation can cause anything from bad user experience to making the whole service unusable. Phone numbers outside North America are not fixed length. Addresses come in many formats. The list is endless. We live in a global world. There is probably not a single site that can be sure to have only "local" users. Ask anyone who moved from one country to another or just tried to plan a bit more exotic holiday trip.
- nephanth 4y agoBut there are sites that explivitely ask for a "local" phone number. Maybe their automated sms system can't send to foreign numbers ? I' pretty sure that's how banks in the us operate Anyway in that case, the front-end should definitely catch it before the backend throws a fit
- mbell 4y agoClient side validation, regardless of the technology used, is a performance and UX optimization. The backend must always validate and it's this validation that matters for any sort of 'security' or data integrity issue.
- wrayjustin 4y agoAs others have said, client-side validation is to assist a user with providing proper values. (Example: Did you forget to type the "@" sign in your email? Did you miss a digit in your phone number?) But also, JS client-side validation is also client side, and therefore exposes the same amount of information to an adversary. Either way, you need input validation on the backend.
- ozten 4y agoFirst example - Image Slider is very janky for me. Firefox, beefy GPU PC, Ubuntu. The purpose of this site is awesome! I appreciate the transparency of pointing out issues like "no user control over images".
- winrid 4y agoInteresting, which GPU? On Windows, it's very smooth for me, but I have a 3090ti... Chrome's task manager says the page is using ~0% CPU, 20mb of GPU memory, and 90mb of ram.
- another_story 4y agoIt worries me we're discussing gpus when it comes to an image slider.
- dspillett 4y agoA surprising amount of stuff that you might think it's done with just dumb bitmap rendering surfaces, is these days actually painted on graphics primatives with it all composited together by your GPU. It likely isn't using much more power than if running at entirely idle, often enough less than the extra a CPU might use doing the same job at a lower frame rate, displaying and updating your current desktop.
- Regnore 4y agoWhy does it worry you? GPUs are designed to push pixels around. This a perfect use of them.
- sgtnoodle 4y agoI think the concern is about the perception that you need hardware capable of drawing 200 billion pixels per second in order to render a webpage.
- heavyset_go 4y agoMost browsers are GPU accelerated.
- Waterluvian 4y agoLove it. Going to play with some of these. It feels a wee bit amusing that it’s about “you don’t need JS” but uses SCSS for examples. I think there’s something powerful and accessible about keeping the complexity to an absolute minimum. I’m not sure this page needs SCSS.
- systemvoltage 4y agohttps://youmightnotneedjquery.com https://youmightnotneedjquery.com is actually a great pitch for jQuery. I still use jQuery, I don’t care. For small things, the API is nice (except the $ sign) and they still continue to publish updates.
- kyleyeats 4y agoIt's not that hard to remove jQuery, using this site, after using it to prototype something. I had 97 $s in a recent file and it only took an hour to convert it. It takes way more time to convert React to vanilla JS. But I think that's been the point of React for long time: lock-in. The current debate over shoving the styles into components or shoving them into the toolcahin boggles my mind. It's driving me crazy.
- hot_gril 4y agoI've never used jQuery before and don't feel like I'm missing much. But these comparisons of how to do something in A vs B are always useful.
- ativzzz 4y agoThis gets posted once a month and everyone who dislikes JS is like YEAA but the reality is these are great for simple websites / apps but once your app starts getting more complex all of these components will start to need to do more things like on click interactions or interacting with other parts of the page or the backend and you'll end up porting it to JS anyway JS is a fine tool for making rich, interactive UIs in the browser and IMO avoiding it at all costs shouldn't be a priority
- Waterluvian 4y agoIt’s not a binary choice. Expanding your toolbelt with this knowledge is like giving yourself an extra set of native functions.
- danielvaughn 4y agoHeck, if you write server side React with NextJS or something, you can return an entirely js-less page even though you wrote it entirely in JavaScript. Have your cake and eat it too.
- onion2k 4y agoThat's true, but if you ask the question "Is Next and JS the best way to do this?" the answer is almost certainly "No". The reason why it's seems like so many devs are doing it this way is because so few devs are being honest and truly critical of their toolset. JS (well, TS) is fine but it's not good. I'm a frontend dev, and I use JS, React and Next daily for making a rich clientside-driven app that uses a sprinkling of serverside rendering to gather up some data every page needs at the start, and it's nice to work with. It's easy and our velocity is great because of it. If we ever go fully serverside with no code shared on the frontend I'll be arguing that JS is the wrong language for the job because we can be faster, and safer, in something like golang. We shouldn't be afraid of abandoning JS if we don't need JS.
- MrJohz 4y ago
- twstdzppr 4y agoYeah, I probably need JavaScript. Preferably TypeScript.
- Spivak 4y agoThere’s really no reason to not to at this point. Building websites with anything other than self-contained components is zero percent worth it. css-as-dry was a mistake. Never again, not even a little.
- sgtnoodle 4y agoThe web site broke the "back" button on my phone. I had to manually navigate back to HN by url.
- deleted 4y ago[deleted]
- adamparsons 4y agoyou might not need a good user experience
- robertoandred 4y agoThe lack of accessibility makes many of these simply non-starters.
- tibbar 4y agoSome of the proposed substitutions, especially the view switcher, use opaque and tricky CSS, the sort of stuff that would show up in mailing lists of CSS hacks in the past. The equivalent javascript code would be much easier for almost anyone to read and debug. Maybe there's a market opening for a tool that compiles javascript to CSS. :shrug:
- deleted 4y ago[deleted]
- LAC-Tech 4y agoI'm waiting for someone to be truly brave, and come out with "you might not need react". I can hear the cries of anguish now. "battle tested! facebook! declarative! library not a framework/if you don't use it you'll end up using your own framework!".
- deleted 4y ago[deleted]
- thex10 4y agoI've been wanting to do this ever since I had a junior dev ask for React for a simple expand to show/collapse to hide text element.
- cloudking 4y agoTIL input type="color"
- mxuribe 4y agoSame! ...so, i had to look it up, and quite interesting indeed: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color https://developer.mozilla.org/en-US/docs/Web/HTML/Element/in...
- yukirock 4y agoI appreciate the work, but I'm feeling some pure visual effects might be unnecessary. When you can scroll effortlessly on a screen and have effectively infinite space, do you still need to squeeze a lot of elements to a small area? Instead of using image sliders, view switchers or tabs, you can consider using a larger container and show all contents at the same time, with the help of js-free flexboxes or grids.
- snowl 4y agoJavascript bad, HTML good. Upvotes to the left.
- jongjong 4y agoJavaScript is the best language for application and API development. People who have a problem with JavaScript need to get over themselves. JS is one of the closest languages we have to pseudocode (which is optimized for readability by humans). It has some bad parts, but you can avoid these and write very secure, high quality code. IMO, the simplicity of JavaScript makes it easier to spot mistakes in the code.
- xupybd 4y agoHave you tried many other languages? This is not my experience at all. I find Typescript to be a world better than JS. You are correct you can write secure, high quality code. You can do that in assembler too. However that's very difficult and it's easy to go wrong. I think JS is better than assembler but there are much better languages. Sometimes we become an expert in something so it's much easier for us to use. Then we think that thing is the reason it's so easy. When it's our expertise that makes it easy for us. Do you think that could be the case?
- hot_gril 4y agoI had a large NodeJS web backend that my teammate and I switched to TS . It just felt like JS but with extra steps. The type system is rather manual (compared to say Rust), and it didn't catch any mistakes I wouldn't have noticed on my own or caught in integration testing. It also complicated the toolchain all the way through. But we rolled with it. The next project was forked from the same codebase and had an even more complex feature set. I took everything back to JS and never regretted it. I've done other backends in Python, Erlang, Java, Golang, and C++. Done mobile apps in ObjC and Swift; not directly comparable, but JS (via React Native) was also nicer like night and day.
- xupybd 4y agoMy experience has been that JS is difficult to maintain. Especially when the project gets a few years old. It might just be personal preference. If you've given other languages a go and still love JS that's great. I'm glad you enjoy it.
- darepublic 4y agoYou might not need scss
- hot_gril 4y agoThese are neat tutorials, thanks for sharing, but I still need Javascript. I can't deal with CSS, and idk what SASS is.
- rsch 4y agoThere are obvious downsides to many of these CSS hacks. Pay close attention to the usage notes. An example not on the page are menus powered by the CSS :hover pseudo-class. It seems smart, until you realise the diagonal problem exists, and it is quite hard to select an item in your menu without accidentally opening one of the sibling menus. Unfortunately, software development seems extremely poor at passing knowledge on to the next generation so you see these problems being “rediscovered” over and over again.
- deleted 4y ago[deleted]
- didip 4y agoThis page is missing 1 more obvious use-case: no-js loading spinner.
- mpawelski 4y agoI'm quite impressed by the scroll indicator, though I have no idea how it works. Also I have a feeling that whatever technique it's using it won't be that flexible to position the indicator anywhere on site.
- sershe 4y agoMy favorite reference point for Javascript use is simple-HTML version of GMail. It's a webapp and it works fine with ~0 javascript. Is your thing more complicated than GMail? If yes, maybe you can use Javascript in proportion to how much more complicated it is. If not and you are still using a ton Javascript, please don't ever write software.
- xigoi 4y agoPlease respect the prefers-reduced-motion setting when adding animations. I don't want to waste my time watching stuff slowly slide around on the page. For the accordion, why not just use <details>?
- deleted 4y ago[deleted]
- bearmode 4y agoThere's no reason to avoid JS to these extents. Half of them look and feel incredibly janky to use as well.
- alexvoda 4y agoI remember also seeing a gridview with filtering without JavaScript but I can not find it.