Javascript on websites
This is just going to be a short little article, but it's something I've wanted to express for a while. Ever since I started learning web development many years ago, I have always had a slight dislike for Javascript. Not the programming language itself, but relying on it in web development. I have obviously come to realize that you can't really build a modern website without it, but I still think that a website should function without Javascript. Before I go deeper into this, I want to give a very simple overview of the most basic components of a website.
At the most basic level, a website is served as HTML, HyperText Markup Language. Basically, it's the text you see on a website, surrounded by some tags that your browser understand. HTML tags just let the browser know if a section of text is a heading, or paragraph, or perhaps a list. Your browser have some defaults for how to display these different elements. For example, a <h1> element in HTML is a primary heading, which will be displayed with larger font than normal text.
Relying on a browsers default way to render these elements is not particularly interesting. A website would look rather terrible if defaults were used, so for styling we have something called CSS. CSS stands for Cascading Style Sheets, and it is what lets us create so many unique looking websites. This is all you need for a website, although there will be some limitations when you compare this with solutions that include Javascript. Obviously, there is more going on behind the scenes, but that falls outside the scope of this article.
So what then in Javascript? It is a full programming language that just about all web browsers can run. This code is executed in the browser on your system. Normally, a website can only update what you see whenever you either refresh the page or click on a link to a new page. With Javascript, you can update elements without the need to refresh the page. This is obviously very useful, I use this myself for some simple purposes. Certain elements will be resized depending on the size of the browser window, and I can post tiny updates that will display without a page refresh. But I still try to use as little Javascript as possible. Unless I really need it, I feel like it adds unnecessary bloat to a website.
There is one important use for Javascript, something that I can't really escape. All the EU rules and regulations are generally making life difficult for web developers. I will admit that some of the rules have good intentions, but the problem is that the rules were made by people who don't understand the technology. This is why just about every website you visit will bludgeon you over the head with these GDPR related messages, asking for your consent to data collection and cookies. It's ugly and annoying, but it is required. I could implement this through backend code, but that would lead to redirects and page refresh. Instead, implemented it with Javascript. It is an easier solution, especially for visitors as they don't have to wait through a page refresh.
I have experienced some websites that use Javascript to load the page just a little at a time. As you scroll down the page you will eventually reach the "end" where you get a little loading icon. After waiting a few seconds that feel like an eternity, more text and pictures is added and you can keep scrolling and reading. I personally hate this with a passion. It is impossible to search on such pages. If the paragraph you are searching for is at the bottom of the page then you have to scroll, wait for the loading and repeat until you finally reach what you were looking for. It also makes it impossible to glance through the page quickly.
Some websites are built around the "one-page" concept, with not a single page refresh. It might be suitable for some websites, but personally I prefer to keep the content on separate pages. It is easy for visitors to share direct links to content and bookmark specific pages.
At this point I feel like I should mention that I browse with Javascript disabled. I manually enable it for websites that I trust, it makes me feel generous when I give websites permission to run code in my browser.
So where does that leave this website? Some functionality requires Javascript, but you can actually browse without it if you so prefer. I will not hold it against you. The only thing that really requires Javascript at the time of writing is the ability to comment on articles. Apart from that, everything else should work.
UPDATE: This website now relies on a bit more Javascript, in particular if you want to support this website by enabling additional features such as Analytics and Ads. These are optional, but also important if you wish to support this website. Enabling these features will require Javascript as they can't run without it.
Categories: Web Development, Programming
You need to Log in to comment.
If you don't have an account, then feel free to Create an account