ELI5 - why so much scripting in basic websites?

bralex

Smack-Fu Master, in training
96
Subscriptor++
Genuine question, not a whine.

I use noscript when I browse, and tons of simple looking websites that (on the surface) don't seem to need any scripting don't work. An example of what I'm talking about is local restaurants with no online ordering. The website is a background, contact info, and a jpg or pdf menu. I'll hit the page, and see nothing at all until I enable at least a few scripts.

What's the motivation or driver there? I programmed some basic web pages at work in the (cough) early 90's (cough) and there was nothing to them - certainly nothing I brag about - but they had more content and complexity than these pages. What is the scripting adding? My only real guesses are tracking metrics of some kind, or that the page designer is using a somewhat overpowered template/tool to design simple pages - the scripting is intended to support complexity that isn't being used.
 

rain shadow

Ars Tribunus Angusticlavius
6,680
Subscriptor++
My only real guesses are tracking metrics of some kind, or that the page designer is using a somewhat overpowered template/tool to design simple pages - the scripting is intended to support complexity that isn't being used.
I think that's a good assessment. I would add that some scripting is just poor man's CDN. The actual restaurant web site may be hosted on virtual web server on a virtual machine provisioned with a pittance of RAM and cpu. The scripts direct the browser to fetch images, videos, tables, css, etc from a more capable host.

Some scripting is for e-commerce integration. A phone number or link to place an order will not be hard coded, instead it will pull in a snippet from e.g. doordash or square that provides the lastest contact info for ordering. Similar for other functions like logging in with FB or apple ID, or accepting credit card info for an order.

Even a simple web site that is built using a wizard may have a lot of scripts just pasted in because it's easier than having the wizard figure out the specific ones that are needed.
 
D

Deleted member 43669

Guest
My only real guesses are tracking metrics of some kind, or that the page designer is using a somewhat overpowered template/tool to design simple pages - the scripting is intended to support complexity that isn't being used.
I think that's a good assessment. I would add that some scripting is just poor man's CDN. The actual restaurant web site may be hosted on virtual web server on a virtual machine provisioned with a pittance of RAM and cpu. The scripts direct the browser to fetch images, videos, tables, css, etc from a more capable host.

That is not needed at all. All those HTML elements use URLs to locate resources, no need of using Javascript for that.

Some scripting is for e-commerce integration. A phone number or link to place an order will not be hard coded, instead it will pull in a snippet from e.g. doordash or square that provides the lastest contact info for ordering. Similar for other functions like logging in with FB or apple ID, or accepting credit card info for an order.

Even a simple web site that is built using a wizard may have a lot of scripts just pasted in because it's easier than having the wizard figure out the specific ones that are needed.

Yes, those things happen.

IMHO, I hate that this happens (I run NoScript even in my smartphone), but I can understand that people learn webdev using React or any other frontend framework, because it's a good way to build highly dynamic websites- where Javascript is needed anyway. However, when they need to build something simpler, they use the same frontend framework- because they already know how to use it. Poof- website that requires Javascript to work, even if it could have been implemented perfectly with no Javascript or progressive enhancement (i.e. web is functional without JS, better with it).
 

hestermofet

Ars Legatus Legionis
25,464
IMHO, I hate that this happens (I run NoScript even in my smartphone), but I can understand that people learn webdev using React or any other frontend framework, because it's a good way to build highly dynamic websites- where Javascript is needed anyway. However, when they need to build something simpler, they use the same frontend framework- because they already know how to use it. Poof- website that requires Javascript to work, even if it could have been implemented perfectly with no Javascript or progressive enhancement (i.e. web is functional without JS, better with it).
That's a big part of it. I've seen websites from my schoolmates back in the day where the entirety of jQuery was loaded just to use $.trim(). The developer never made anything without a library like jQuery, and apparently doesn't realize that Vanilla JS already has a trim function, I guess? These are the types of developers university-level CS programs are graduating nowadays. They don't teach you anything that makes you a legitimately useful employee, they just train you to be a mathematician whose talents are better used in some stuffy office in the bowels of a university math/CS department, but can't actually write 10 lines of elegant, readable, usable code.

I work with Java, and the number of times I see import org.whatever.* instead of the particular package that you're actually using is effing maddening. The way you import libraries in JavaScript is fricking stupid. JavaScript, in general, is just plain stupid. The only solution without breaking billions of lines of code would be a preprocessor for JS like there is for CSS... like SASS, or something. Is there one? I don't really do front-end development. Not really sure that SASS does what I'm talking about, TBH, only used it briefly.
 

iljitsch

Ars Tribunus Angusticlavius
9,637
Subscriptor++
Partial answer to the question:

Javascript can be really useful. I never really liked it, but now on my personal site I use it to adjust zooming on iPads and iPhones, especially when rotating the device from portrait to landscape or the other way around, as well as delay loading lots of images and more.

Obviously, it's important to keep in the back of your mind that people may not have javascript, and the page/site still needs to work. I do keep that in mind, but I have to be honest: I rarely test for this. Lazier people will just not think about such issues at all.

That being said, I have no idea how the web became this cesspool of inscrutable javascript code that does stuff that can easily be done with plain HTML and CSS.
 
D

Deleted member 43669

Guest
That's a big part of it. I've seen websites from my schoolmates back in the day where the entirety of jQuery was loaded just to use $.trim(). The developer never made anything without a library like jQuery, and apparently doesn't realize that Vanilla JS already has a trim function, I guess?

In many cases, jQuery "fixed" stuff that was missing in some browsers, or which had issues. I remember specifically the AJAX stuff, for instance. jQuery's trim is deprecated (since last year!)- there's a chance that at some point it was useful (or it might not, but jQuery is mostly reasonably well-designed. I think having a trim *function* might be because it's useful to be able to invoke it on nulls.

These are the types of developers university-level CS programs are graduating nowadays. They don't teach you anything that makes you a legitimately useful employee, they just train you to be a mathematician whose talents are better used in some stuffy office in the bowels of a university math/CS department, but can't actually write 10 lines of elegant, readable, usable code.

CS = Computer Science != coding. While I'm sure university could produce people who are better codes without detriment to producing academics (both academics and coders are required in this world), I could also say that it's likely there should be specific career paths to become a professional coder, and to become an academic.

I work with Java, and the number of times I see import org.whatever.* instead of the particular package that you're actually using is effing maddening.

I'm sure there are worse things that are bothering you on those pieces of code.

The way you import libraries in JavaScript is fricking stupid. JavaScript, in general, is just plain stupid. The only solution without breaking billions of lines of code would be a preprocessor for JS like there is for CSS... like SASS, or something. Is there one? I don't really do front-end development. Not really sure that SASS does what I'm talking about, TBH, only used it briefly.


You mean Typescript. Or any of the languages that compile to Javascript or WASM. This weekend I finally pushed a first operating version of a PWA I'm writing as a side-project with Rust- you are certainly not forced to go through Javascript.

If you are writing a non-heavily dynamic website, then you don't need to write a ton of Javascript, and then it's tolerable. If you have to do a very dynamic app-like-thing, then investigate TS or whatever (Elm, Clojure, the Haskell-JS thing, etc.).

Partial answer to the question:
Javascript can be really useful. I never really liked it, but now on my personal site I use it to adjust zooming on iPads and iPhones, especially when rotating the device from portrait to landscape or the other way around, as well as delay loading lots of images and more.

Obviously, it's important to keep in the back of your mind that people may not have javascript, and the page/site still needs to work. I do keep that in mind, but I have to be honest: I rarely test for this. Lazier people will just not think about such issues at all.

It's démodée to do progressive enhancement, but back in the day I tried doing that and it didn't work so badly. You basically sprinkle JS on top of a working page without JS. It's hard to remember to keep testing without JS when making changes, but if you do things in a certain way, it's likely that your website will be mostly functional on NoScript.

That being said, I have no idea how the web became this cesspool of inscrutable javascript code that does stuff that can easily be done with plain HTML and CSS.

Again, people being lazy and applying JS frameworks to pages that do not require that. There's a case that can be made about that being cost-effective, and that only a minority cares about the drawbacks.
 

hestermofet

Ars Legatus Legionis
25,464
CS = Computer Science != coding. While I'm sure university could produce people who are better codes without detriment to producing academics (both academics and coders are required in this world), I could also say that it's likely there should be specific career paths to become a professional coder, and to become an academic.
Agreed. There's definitely value in CS programs, but a lot of people go that route expecting to end up in industry. I don't think that's the right route to take. In my country, we have two levels of higher education, university and college. University is academic, college is technical/hands on. College is really looked down on. University is a lot more popular across all fields, even non science ones. I did both, university for an arts degree and college for programming. Comparing my experiences to colleagues and friends who did CS in university, they did very little actual programming in school so they tend to suck when they graduate. Hard. The good ones ramp up quickly in their first few jobs, so it doesn't matter in the end. But you still end up with a lot of developers on the job market that look like they are qualified on paper, but when you go to interview them, you find their skills are sorely lacking.

You mean Typescript. Or any of the languages that compile to Javascript or WASM. This weekend I finally pushed a first operating version of a PWA I'm writing as a side-project with Rust- you are certainly not forced to go through Javascript.

If you are writing a non-heavily dynamic website, then you don't need to write a ton of Javascript, and then it's tolerable. If you have to do a very dynamic app-like-thing, then investigate TS or whatever (Elm, Clojure, the Haskell-JS thing, etc.).
Neat! Like I said, I don't do anything front-end professionally, I work a lot with databases (I'm doing ETL right now) or LOB apps.
 

Lt_Storm

Ars Tribunus Angusticlavius
21,346
Subscriptor++
IMHO, I hate that this happens (I run NoScript even in my smartphone), but I can understand that people learn webdev using React or any other frontend framework, because it's a good way to build highly dynamic websites- where Javascript is needed anyway. However, when they need to build something simpler, they use the same frontend framework- because they already know how to use it. Poof- website that requires Javascript to work, even if it could have been implemented perfectly with no Javascript or progressive enhancement (i.e. web is functional without JS, better with it).

There is nothing inherent to a website built with React that means it necessarily requires JS to work in the browser. Server side rendering is a thing and it is entirely possible to do progressive enhancement with a tool like React. Just because most people don't bother / don't have any idea how to do so doesn't mean that the tools don't enable it.
 
D

Deleted member 43669

Guest
There is nothing inherent to a website built with React that means it necessarily requires JS to work in the browser. Server side rendering is a thing and it is entirely possible to do progressive enhancement with a tool like React. Just because most people don't bother / don't have any idea how to do so doesn't mean that the tools don't enable it.

There's nothing inherent about it, except that by default there is no SSR, the main React site hardly mentions it (I did find a link to Gatsby, which I believe does SSR) and that we're talking to people who use React to do mostly static sites using React because that's what they know- those are certain likely to never have bothered about SSR or not even know it exists.

Yes, most frontend frameworks allow you to work only on specific elements of pages, but what I'm seeing in the wild most of the time is doing everything using the front-end framework, and doing routing using JS, which means a blank page when using NoScript.

The OP's experience matches my experience- running NoScript results in a ton of white, empty pages, which 99% of the time are caused by pages using a JS frontend framework for everything in the page, down to routing. I don't have the data to prove this, but when a page works well with NoScript, it's normally because it's a traditional website with some JS on top. For instance, on these forums, the spoiler tags don't work, but mostly everything else works well.

You can make frontend frameworks work pretty well- not just SSR rendering, but making URLs, back buttons, etc. work correctly. The thing is, many developers don't care about that (perhaps *rightfully*). And this is not a fault exclusive to JS frontend frameworks, some stuff like JSF and other backend frameworks cause issues in those regards.