2

I'm under the impression, and I agree with it, that it's bad to create a web application requiring JavaScript to function properly.

What if one were to create a single page application? Is it possible to create one that doesn't rely on JavaScript, without being difficult, or full of "hacks"?

Nathan Lutterman
  • 359
  • 1
  • 4
  • 10
  • 6
    Do people really think it's worth it to try to make the functionality of your site work without javascript in this day and age? That's a lot of extra work. Is that extra work really justified in the amount of additional viewers you'll have versus spending that same amount of time on additional functionality for your site? – jfriend00 Oct 16 '13 at 23:15
  • I would be very careful of why you think its bad to require Javascript, in some cases you might want to do that , but in the modern age this has become more of a dogma then a real need. For sure if there is a good reason to avoid JavaScript then that is reasonable, but doing it just because its "Bad" is probably not in the best intrest of the project. – Zachary K Oct 17 '13 at 00:50
  • There's a reason certain browsers don't even have a toggle anymore for enabling/disabling JS... – Stefan Billiet Oct 17 '13 at 06:19

7 Answers7

7

The short answer to your main question is "no". You cannot write a single-page app in the conventional sense without relying on JavaScript. The common definition of an SPA is using a combination of rendering on the client-side using DOM manipulation and AJAX calls to provide a fluid, responsive client experience. By definition, this includes the use of JavaScript.

You could make the argument that Java applets or plugin technologies like SilverLight and Flash provide a similar quality of experience and can involve only a single page load, but this is not generally what folks mean when they talk about SPAs. Further, plugins are less likely to be installed and active on a user's browser than plain old, ubiquitous JavaScript.

In terms of the goodness or evil of JavaScript, others answers have addressed it well. JavaScript is now widely accepted and there is little reason to hesitate in using it for web applications, even if they are not SPAs.

DemetriKots
  • 1,188
  • 8
  • 14
  • +1, *"You cannot write a single-page app in the conventional sense without relying on JavaScript"* You would think this would be self evident, but apparently not. – GrandmasterB Oct 17 '13 at 04:15
  • True. It's the javascript that makes it an _application_. Without javascript, it's just a _single page_. – Eric King Oct 17 '13 at 23:51
5

I'd say no. It could've been bad 5-10 years ago to create a web application that requires JavaScript, but technology is advancing, and as such, web applications are becoming more dynamic, and require proper processing technology. This is where JavaScript comes in.

Single page web applications are likely to be even more heavily reliant on JavaScript, as they tend to make strong use of AJAX calls to show data.

At the end of the day, you could theoretically make a single page application in server-side code such as PHP, but the quality of the website will be severely lacking in comparison to one that takes full advantage of the technology available today.

Ben Harris
  • 174
  • 1
  • 1
    I am not clear on how one could build a single page app using PHP. By definition SPAs rely on AJAX and client-side rendering, implying javascript. I am not very familiar with PHP, but suppose you could build a server-side rendered app that relies on a single PHP page that switches content based on user session state and url parameters, etc., but I don't think this is really what most people mean by SPA. Am I missing something here? – DemetriKots Oct 17 '13 at 00:23
  • No, I think he means you could write the app in a single code file. Which would probably be an abomination in and of itself. Then again more than a few SPA's are written this way . . . – Wyatt Barnett Oct 17 '13 at 03:25
  • 2
    @DemetriKots You still need to pull AJAX data from some kind of source for your client-side application, that's the server-side of things hence PHP, ASP.NET, NodeJS or whatever. SPA doesn't really dictate what kind of server-side technology you use. – Spoike Oct 17 '13 at 05:58
  • Now I've never been an intense developer for internet applications, but I was thinking about "graceful degradation". I was just always given the impression that relying on any one technology for a service was a bad thing. I have not personally disabled JavaScript for any reason, other than to test whether a website works without it. I came here to ask because I was not sure. – Nathan Lutterman Oct 17 '13 at 07:18
2

I remember people making this argument 10 years ago and even back then I thought it was ridiculous. Apart from the utter uber-geek who represents 0.01% of the population, no-one turns off javascript these days. No-one. I hate to be dogmatic about this but look at the biggest websites - gmail, facebook, twitter, youtube - they all need javascript to work.

The only thing to be careful of is security - you can't rely on javascript for validation because the user could turn it off - or even worse, alter it.

Rocklan
  • 4,314
  • 1
  • 15
  • 29
  • Doesn't Gmail have a simple HTML mode that works without Javascript? Or does that need Javascript too? – Artur Gaspar May 31 '15 at 10:41
  • Simple HTML Gmail isn't a SPA (Single Page Application). Of course you can make a web application completely without javascript, but not on a single page. – roetnig Jun 02 '16 at 09:33
2

Let's see. So right now, I can build apps on the desktop using Roger Wang's node-webkit, write server-side code that just works without fiddling with 18 layers of config and absurdly over-complicated servers that refuse to just do the 'duh' things right out of the box, write phonegap/cordova apps for Android, IOS, Winphone, and several other platforms simultaneously including desktop mostly reusing the same code in Roger Wang's node-webkit (highly recommend btw - thanks Roger). I can write Linux GUIs in JS. I can do damn near anything Microsoft using web technology...

So uh... yes. I would say the answer is yes. But it's not just JS. If you really want to be able to handle UI well, you have to learn the crap out of CSS. Once the crap has been learned out of, you can do damn near anything including performance critical-stuff with a little help from our friends C and C++ bound easily to JS through V8.

And you can't be a Java dev about it and write once and test nowhere. You do actually have to learn the quirks of the platforms you're supporting. There is no multi-platform solution that has negated that but I would argue that web technology and web UI devs have taught the planet how to finally !@#$ing do it right.

So learn more and it will be less difficult. Learn to properly normalize for multi-platform and use OOP to your advantage and you may be shocked at just how maintainable and lean and mean a well-written and non-hackish JS app that handles multiple interpretations of what its code actually means can be. Take a trip down memory lane on Quirksmode. Read the first edition of DOM scripting. Pay a visit to Dean Edwards's site and blow some of the dust off of some his still-completely-relevant-and-awesome ideas. We've been at this "demanding that our JavaScript function properly" thing for quite a while now but I'd say it probably really kicked in when everybody realized just how freaking useful and powerful the DOM + CSS2 + and JavaScript could be (well before people started tinkering with XHR and assigning undue importance to Ajax's contribution to the evolution of the modern web app).

As far as I'm concerned, and I've been exposed to PHP, Python, C#, Java, and Ruby professionally, no language as popular and widespread wraps, adapts and normalizes as well as JS. Nothing. This may have something to do with why it has spread from the client-side browser like wildfire and you're finding yourself irritated that you keep running into it all over the place.

Erik Reppen
  • 6,243
  • 31
  • 34
1

Yes it's possible. The way to do it is to create a multi-page application first, then progressively enhance it into a single-page application. In your client side code, you use the HTML5 History API to manipulate the URL so that if the app is bookmarked at any time, then the bookmark will show the same page or application state no matter which browser the bookmark is opened on. Is it a lot of work? Yes, but this is indeed the pattern that's usually followed to make single-page applications that work without JavaScript.

One famous example is the GitHub Tree Slider.

user16764
  • 3,583
  • 1
  • 25
  • 22
  • 1
    Isn't the HTML5 History API a JavaScript API? – DemetriKots Oct 17 '13 at 00:51
  • @DemetriKots Yes. You use it in your client side code, as stated, to handle the fallback to the JavaScript-free, multi-page version. See the link – user16764 Oct 17 '13 at 02:55
  • I see. You are basically suggesting graceful degradation when JavaScript isn't available. That wasn't how I read the question, but your answer makes sense in that context. – DemetriKots Oct 17 '13 at 03:42
1

You can use methods like post-backs, server-side validation, etc. as fallbacks for non-javascript visitors. It won't be seamless as it requires, at the least, multiple page loads, but it can be done.

Todd
  • 141
  • 4
1

Is it possible to create [a Single Page Application] that doesn't rely on JavaScript, without being difficult, or full of "hacks"?

Yes, you can…

If the definition of SPA is that you have only one point of entry for your web application, then you can definitely create an SPA without Javascript.

Unfortunately you'll only have one page relying on complicated postbacks.

I'm under the impression, and I agree with it, that it's bad to create a web application requiring JavaScript to function properly.

Why are you under such impression, really?

You might want to have a look at your server stats and see how many users have Javascript disabled. There is a pixel service for this as well. I haven't seen any stats on places I've worked at where this is above 1% for several years.

If you're working with sites where disabled javascript/css is a requirement then SPA is probably not the best option for you. I can imagine users with cognitive disability (such as visually impaired users) or anyone with a screen reader will have a difficult time navigating an SPA site.

Spoike
  • 14,765
  • 4
  • 43
  • 58
  • The only reason I was under the impression was because I've read several answers to similar questions such as:[SO-1084076](http://stackoverflow.com/a/1084076);[SO-822893](http://stackoverflow.com/a/822893);[PSE-149024/90762](http://programmers.stackexchange.com/a/149024/90762); I know these aren't necessarily geared toward Single Page Applications, but I thought the sentiment was the same. – Nathan Lutterman Oct 17 '13 at 07:22