Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
Autumn, 22 Nov 2026 - @500.39
Forum Activity: Three Stars ~ Boop! The forum will close in 500.beats! Random | Recent Posts | Guild Recents
News: There's a great big indie web tomorrow! :smile: Guild Events: November 200 words RPG jam
+  MelonLand Forum
|-+  Da Web Revival
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Why to avoid Javascript, and when is it appropriate?


« previous next »
Pages: [1] Print Embed
Author Topic: Why to avoid Javascript, and when is it appropriate?  (Read 57 times)
Limette
Full Member ⚓︎
***
View Profile WWWArt


⛺︎ My Room
iMood: Limette
RSS: RSS

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!I got robbed by Dan Q on Melonland!Joined 2025!
« on: Today at @408 » Toggle Font Embed

A common consensus on the indie web seems to be that Javascript should be avoided as much as possible. I think I get why, after all JS tends to make sites slower and stuff. Personally I avoid using JS for my website because I'm inexperienced with it and am worried about writing or copying code that I don't fully understand. It has also become a bit of a badge of honor, to be able to find pure CSS solutions to JS problems (even if I'm mostly copying other people's code snippets) and make the claim that my website is not only fully functional without- but also just genuinely doesn't use JS.

But the more I bash my head against the wall that is CSS and find myself having to give up on features where JS cannot be circumvented, I ask myself: Why am I doing this to myself? What did JS do to me, besides being harder to learn? At what point does it make more sense to use it than to not?

I ask myself this question a lot when I consider the gallery page of my website. Currently this gallery is tabbed and has "pop-ups" for the full images and their descriptions, both done fully through CSS. (Courtesy of a tutorial by Dan for the gallery and another one by... I think it was CSS-Tricks? for the tabs.) It loads really fast, I understand how all of the code works, and I'm rather proud of myself for being able to work it out... but it does come with a huge drawback, at least if I want my website to be my main avenue for sharing my art: I can't link to specific tabs or artworks. I looked into it, and it seems genuinely impossible unless I replace my pure HTML/CSS code with one that involves JS.

And so I have to wonder: what is more important to me? To have my gallery be fast, and accessible even for users that have JS disabled, or to be able to link to specific artworks from my website?

Since <noscript> exists, would it be possible to delegate my CSS-only layout to that? That way the gallery would be functional even with JS disabled, but I also get to have more specific links...

Logged

https://limette.neocities.org/assets/limette.gifhttps://file.garden/aJDdYDydqnG0q1NR/blinkies/exinc.gif
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Caught by RubbereonThe Worm is creeping around Melonland profiles!Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #1 on: Today at @461 » Toggle Font Embed

<noscript> ain't all that IMHO

<noscript> isn't a perfect solution, because <noscript> content only gets rendered if JavaScript is disabled. But JavaScript being disabled isn't the only reason that you'd want "no script" fallback content to be displayed. Other reasons include, for example:

- a bug in the JavaScript code halts its execution
- the JavaScript code uses features that do not work in the user's browser (e.g. new functionality, or a dependence on a not-available API)
- the JavaScript file is blocked (e.g. by a misbehaving adblocker)
- a dependency of the JavaScript fails to load (e.g. misbehaving or blocked CDN, ISP or country-level censorship, etc.)

None of these will result in the <noscript> being shown. The user just gets a broken experience: JavaScript is fundamentally more fragile than HTML and CSS, on average.

Personally, I'm not a fan of <noscript>. Here's my preferred approach: I do this:


Code
<body class="no-js">

<!--
  HTML code goes here. Any HTML that DEPENDS on JS goes in a
  <div class="needs-js">...</div>
  Any HTML that is fallback goes in a
  <div class="needs-no-js">...</div>
-->

<script>
// Essential JS goes here.

// Only when it's all run successfully do we do this:
document.body.classList.remove('no-js');
document.body.classList.add('yes-js');
</script>

</body><

With this, the <body>'s class changes from "no-js" to "yes-js". This means that we can have some CSS like this to control which interface part(s) are shown:

Code
.no-js .needs-js,
.yes-js .needs-no-js {
  display: none !important;
}

This approach is better IMHO because if your JS code crashes half-way through, you still see the no-js interface.

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif https://origami.danq.dev/88x31.gif https://skelly.monster/dem-bones-88x31.gif

Artifact Swap: Pink ham-ham rangerPolyamorousI met Dan Q on Melonland!shoeJoined 2025!cinnamoroll
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Caught by RubbereonThe Worm is creeping around Melonland profiles!Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #2 on: Today at @474 » Toggle Font Embed

Where I use JS

I use JS in around two circumstances:

1. Where there's no other way. skelly.monster absolutely 100% requires JavaScript. No two ways about it. Where it's not too hard, I try to make an equivalent that doesn't: e.g. when I embed one of the (JS-based) graphs from my blogging stats page into a blog post, I often embed a screenshot of that graph and replace it using JS... so that if JS fails, you still get the static image version (this is also useful for people who prefer to follow me in their RSS reader: RSS readers - for good reason - don't typically allow sites' arbitrary JavaScript to run!

2. As part of a progressive-enhancement strategy. Suppose I want an "accordion"-like interface: vertical tabs, where opening one closes the others. I can get an approximation of that using <details>/<summary> elements, and have something that works for everybody... and then I can enhance that with some JavaScript that detects when one opens and closes all the others. Most people (with working JS) will get a full accordion interface; people without JS will get a series of foldable <details> blocks. Sorted!

HTML Web Components

For that latter strategy I'm a big fan these days of what Jeremy Keith calls "HTML Web Components". The idea is that you use HTML to write as much of the functionality as you can, for maximum accessibility and usability and resilience... and then you "wrap" it in a Web Component that swaps-out the contents for something that gives more functionality!

I provide instructions for example to allow people to use my <embed-html> component in this way! A developer can write this, for example:


Code
<embed-html cache src="menu.html">
  <p>To navigate my site, <a href="menu.html">use the menu</a>.</p>
</embed-html>

...

<script type="module" src="embed-html.js"></script> 

That <embed-html> element contains a basic HTML representation: a link to a menu page. But once the embed-html.js module loads, it gets "swapped out" for the actual contents of menu.html using JavaScript. If the JavaScript works, the visitor sees the site menu. If it fails for any reason, the visitor sees a link to the site menu. Either way, they're able to fully use the site! That's the magic of HTML Web Components!

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif https://origami.danq.dev/88x31.gif https://skelly.monster/dem-bones-88x31.gif

Artifact Swap: Pink ham-ham rangerPolyamorousI met Dan Q on Melonland!shoeJoined 2025!cinnamoroll
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
Caught by RubbereonThe Worm is creeping around Melonland profiles!Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #3 on: Today at @476 » Toggle Font Embed

But your actual question was "when is [JS] appropriate?"...

And the fundamental truth is that it's your site; so it's up to you! Don't let anybody - not the "minimal JS" nuts like me, nor the "JS everywhere" fanboys on the other side - tell you what to do with your own website! Just work to understand the limitations and make up your own mind!  :cheesy:

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif https://origami.danq.dev/88x31.gif https://skelly.monster/dem-bones-88x31.gif

Artifact Swap: Pink ham-ham rangerPolyamorousI met Dan Q on Melonland!shoeJoined 2025!cinnamoroll
Limette
Full Member ⚓︎
***
View Profile WWWArt


⛺︎ My Room
iMood: Limette
RSS: RSS

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!I got robbed by Dan Q on Melonland!Joined 2025!
« Reply #4 on: Today at @495 » Toggle Font Embed

But your actual question was "when is [JS] appropriate?"...

And the fundamental truth is that it's your site; so it's up to you! Don't let anybody - not the "minimal JS" nuts like me, nor the "JS everywhere" fanboys on the other side - tell you what to do with your own website! Just work to understand the limitations and make up your own mind!  :cheesy:


When I really think about the function I want my gallery to serve, I think I won't get around having to learn some JS for it...

The reason I made this whole website, really, is because I didn't want to be bound to social media anymore when it came to hosting and sharing my art. On a personal website, I get to have full control over what I can or can't upload, and how it is presented to users. But there's an important thing that the current gallery can't do: I can't link to (or even better, embed!) specific images.

For that, I think I'll have to finally learn how to work with JS. Though, the idea of making a gallery that can have individual image links, maybe even image embeds, while also being functional if JS fails, sounds incredibly daunting. I don't even know where to begin with that, considering my JS knowledge kind of starts and ends at [alert("Hello, World!");]. I don't know how to work my way up to what I'm trying to achieve, but I guess I have a new goal for my roadmap.



Logged

https://limette.neocities.org/assets/limette.gifhttps://file.garden/aJDdYDydqnG0q1NR/blinkies/exinc.gif
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Guide | Rules | Whos a Mod? | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 Melon
Land
Forum Art Hub Chat Webring Explore Random Recent Tenement Arcade Want to Login or Join ? Web Craft Guide Graphic Catalogue Wiki Help I'm Lost! Link Land Newsletters Image Stream Minecraft: Online
Zap!
Passport Sites tamaNOTchi Asatte Add your site?
Aero Archive Onio Cafe 32 Bit Cafe Status Cafe