In my personal experience in small web circles, I tend to see a lot of opinions about not using JavaScript on your website (or making minimal use of it) with the cited reasons being that it’s insecure and makes your site slower. Plus, people who choose to turn off JavaScript by default will have a harder time using your website.
I personally have made minimal use oc JavaScript for the simple reason that I haven’t learned it yet and am hesitant to just keep using others’ code. Thus I don’t know enough about it (or web development in general) to be able to judge these claims on my own beyond them being genuine concerns people have.
As I keep learning though, and keep seeing some of the cool things people who do choose to have JavaScript on their site are able to pull off, I was just curious about everyone’s general opinions on this matter. Is it really as bad of an idea as I’ve seen some people make it out to be? Is it fine? Or is it in some weird grey area in between?
In my personal opinion, it’s more of a problem if you can’t access the site at all without Javascript, like the way most modern webapps like social media work. I think using a bit of Javascript to have a neat feature on your site is mostly okay, as long as everything is accessible to everyone using the site. (I think that’s the other big problem with lots of Javascript or eg. loading content via Javascript, the site can become unusable for users who might be using screen readers or certain browsers.)
That’s just my opinion though, there could be other stuff I haven’t thought of.
i think a lot of people are just contrary :P and i thiiiink a lot of modern web dev stuff relies really heavily on javascript even for things that can be done in html & css, so people coming from a web dev background are coming from an angle of being annoyed about that!
I won’t speak for anybody else, but I don’t like to use JavaScript on my website because I don’t think it’s necessary. I think I can implement all of the functionality I want for my website with HTML, and a little CSS.
Also, I honestly think that the way we do CSS and JavaScript is entirely wrong. The only CSS and JavaScript your browser should be running is CSS and JavaScript you’ve asked it to run. You should be able to specify user CSS and user JS through your browser’s preferences.
It should not be running any random code to which a web page links. That’s a security risk, particularly with JS. Without it, it would be harder to implement adtech, analytics, and other nefarious shit like crypto miners. It’s also a system that depends on presumed consent, which isn’t consent at all.
As matters currently stand, somebody coming to my website is lucky that all I’m sending them is HTML and CSS. If they’re like most people, and don’t know what they’re doing I could run any sort of code I wanted on their computer for no better reason than that I bloody well can.
That should scare you. It scares me, and I do this shit for a living.
Good points, all! I will usually do two versions, yes, I know, groan! But I want a version with all the bells and whistles and one that is accessible to as many people as possible (everyone I don’t think will ever be possible, though I hold out hope). Just don’t look at my current for a demonstration of any of that. (laziness is love right now)
It’s your website. It’s your decision. If you want to do two versions – one fancy and one accessible – there’s nothing wrong with that. Better still if you’re using progressive enhancement and feature detection so that browsers that cut the mustard get the “good stuff”.
I made perhaps dozens of games in Javascript. Hardly anyone would have played them if they didn’t run in a browser tab. I also find apps like Feather Wiki or Decker very useful for parts of one’s website (never the homepage). If people disable scripting or use a text-based browser, that’s okay, I have lots more stuff to show them.
JS is a tool. Used in moderation, it can make a site more useful and fun. The trick, as always, is knowing where to stop.
The way I see it, there are a number of different things going on, that affect your decision about whether or not to use JavaScript for your site.
You don’t need JavaScript. You can build really good sites (both functionally and aesthetically) without it. My site currently has no JavaScript, neither does @starbreaker’s above, and lots of other people’s here. If you’re willingly to use a static site generator, you can do a lot of “dynamic” things on the server, and give your readers only HTML and CSS (like my tags section). Personally, I think this is the responsible thing to do. Why make your readers spend power and cycles over and over when you can do it once on your end?
Thanks to modern CSS, you can do a lot of dynamic and interactive things without JavaScript. Just look up “CSS animations” to see what’s possible today.
All that being said, there are still some things you might want to use JavaScript for. Right now, the biggest gripe for me is that there’s no way to do proper margin notes, or popup notes without JavaScript. I’m doing something close with just HTML and CSS, but it’s not quite right. I will very likely add a little bit of JavaScript to enable this. I think a judicious use of JavaScript to do something that’s lightweight and actually useful to your readers is fine.
The big problem comes from the fact that the modern web is actually two things: it’s a network of documents (which covers most of our personal sites) and it’s also an application platform. It’s that last part which has led to a proliferation of often unnecessary JavaScript for little to no benefit. Alex Russell has a detailed, multi-part series on the perils of excessive JavaScript.
So, tl;dr a little bit of JavaScript to do something actually useful on your site is probably fine. Shoving multiple megabytes of frameworks and libraries down your visitor’s throats to do what you could do with some HTML forms, not so much. Now excuse me while I go turn all of this into a journal entry.
This might seem needlessly pedantic, but I don’t regard using a static site generator as doing things on the server. Rather, with a SSG you’re mostly building locally and pushing the result to a server. Likewise with my makefile and shell scripts.
You can do stuff on the server using PHP, CGI scripts, or Apache-style server-side includes. That’s how content management systems like Kirby, Django, and WordPress work.
Technically you can run an SSG directly on the server, if you have shell access to it. That’s a smoother workflow than build-and-push. Speaking of which: I recently discovered the Marmite static site generator, which uses a JS library to implement search on the client side with a prebuilt index. If you have scripting disabled, search won’t work, but the site does. That’s what graceful degradation means: everyone can enjoy your creation, but maybe not with all the bells and whistles. Which is a lot better than not at all.
@basus, are you using popover? It’s a relatively new addition to HTML5, and not considered “baseline” until this year, but I think it’s pretty sweet.
@nosycat, you’re right about running a SSG on the server if you’ve got shell access, but I’m not convinced it’s a smoother workflow than build-and-push for the following reasons:
If you aren’t editing your files on the server, you’ve still got to get your raw files to the server.
Local builds make local and offline testing possible.
Well, yeah, I mean if you write your posts over SSH. And local-first means having a backup from the start among other advantages. But different workflows are possible.
are you using popover? It’s a relatively new addition to HTML5, and not considered “baseline” until this year, but I think it’s pretty sweet.
I discovered popup while tweaking my sidenotes a couple days ago. It has promise, but AFAICT there isn’t a way to anchor popups to particular elements on the page. IIRC there’s a draft to add that functionality, and if it goes mainstream, I will move to it.
All good points so far! And a lot of stuff I didn’t know. And yeah, the assumed consent to just run code is scary.
So far, I’ve only used JavaScript for one side attraction on my site. If you don’t want to have JS turned on, then you won’t miss out on much there. Just a silly personality quiz, which isn’t even everyone’s cup of tea.
So, most likely, I’ll keep my use of JS to just that.
I realize this isn’t a popular view, but I’m with @nosycat on this one–I’ve used Javascript to make so many wonderful tools and games, and I love that it enables application development directly in the browser. Sure, there are security issues, so I try to remain open about what my programs do and stick to best practices myself, and I make sure everything can degrade properly where possible. The things I’ve built can reach so many more people due to the fact that they don’t have to be downloaded and run directly in the operating system.
For simple static sites, though, I do agree there’s no reason to use frameworks or overly complicated scripts. I do a full-body cringe every time I see someone set up a simple read-only, non-interactive site using a full React framework or something similar. It’s so overkill for something that could be served via plain text and simple HTML!!!
I don’t really think JavaScript is bad… But as someone who spent some time with JavaScript disabled on my phone, I definitely think it often gets used badly. Like others have mentioned, heavy frameworks are overkill for most personal sites; it’s infuriating to encounter an entirely blank page, reload with JavaScript, and find that it’s just a blog that could have been rendered server-side or made with an SSG. It can also be hard to make things accessible when you have lots of unnecessary interactive elements — a lot of frameworks don’t manage focus properly, or developers don’t know how to do so, for example.
On the other hand, while I don’t have JavaScript on my site yet, I do plan to add it. I’m a big fan of progressive enhancement, and there are certain scenarios where adding a little bit of JavaScript can make an experience more accessible.
Take my first code jam entry, which uses nested details elements. At the moment there’s no JavaScript, and I think it’s great that we can now make disclosure widgets with just some HTML. But at the moment your place in the interactive story isn’t saved; all of the details elements close upon reloading, which isn’t good for cognitive accessibility. Some people (including me!) might not remember where they were in the tree of nested elements.
So my plan is to eventually create a small “autosave” function using local storage and provide a “restart” button to close everything. It will still work when JavaScript is disabled or someone’s connection drops the file, but it will be slightly more accessible to most folks.
I think a lot of web developers, especially those new to the trade, learn JS and a framework like React, Vue, or Angular first. Any HTML or CSS they pick up along the way is incidental.
Either that, or it’s some kind of flex, like overengineering a personal website is something to be proud of. (says the guy who built his own static site generation toolkit and calls it Jocasta)
Honestly, most of it is personal preference in my opinion. I started with JS & HTML, just learning it for fun when I was 12. I didn’t bother with stuff like Vue.js until I was working as a web developer and absolutely loved it, it made web development 10x more fun for me by taking out most of the hassle and allowing me to put things together as fast as I can think about it, while being terrifically lazy!
I will say these days, vanilla JS has come far enough that a lot of the hassle I’m thinking of has been reduced anyway, but WebComponents for example are definitely still nowhere close to Vue.js in practicality & fun for me.
JavaScript isn’t as bad as some will make it out to be. As long as your website is still usable with JavaScript disabled, I don’t think there’s a problem. The implied consent to run arbitrary code is insane to me as well, but at least browsers sandbox your tabs nowadays to minimize security impact.
My issue with JavaScript is that it just doesn’t make much sense to me as a programming language. It does a lot of things completely differently than any other language I use and it confuses me. TypeScript addresses some of these issues but the fundamental design is still the same.
Yeah this is really the crux of it. The web is used as basically a cross-platform UI framework for modern software. While I understand the reasons why this has happened, it seems like such a bonkers solution to the problem. The tech used for making rich software applications has leaked over into the network of documents side of the web, which is where a lot of the anti-JavaScript sentiment comes from.
I’ve accidentally become a fullstack dev over the past year and vue.js has actually been great to work with. I can use a little or as much as I need which is a great benefit.