views:

89

answers:

4

Suppose I'm developing a web app that is heavily dependent on JavaScript and which uses AJAX for all the POST commands to store data, etc.

How should one deal with those situations where a user may have JavaScript turned off? Is it unreasonable to require that a user's browser has it turned on? Are there any best practices for these situations?

+4  A: 

Use <noscript> tags to let users know that they cannot use the site without Javascript. It's not the best practice, but it is common at this point and most users without it will have experience being left out in the rain.

That said, if you can provide a version of the site that doesn't require Javascript (think the degraded version of gmail), that is clearly a superior solution. Without it, you will lose mobile surfers, plus blind folks and others with accessibility needs. And people who are too stubborn to use JS, but we don't care about them.

Joseph Mastey
+1: noscript tag is a must. But if possible give them a useful taste if possible without the scripting.
Pat
+4  A: 

I personally think it is not that big of a requirement to expect people to have Javascript turned on.

If you do not want to support non-javascript, it is as simple as:

<noscript>
    This site works better with Javascript turned on.
</noscript>

Near the top.

If you still want to support users without Javascript, you can structure your Javascript so that if the JS isn't loaded, all of the forms still submit to the right place.

For instance, if you have a form:

<form action="" method="POST">
    <input type="text" name="name">
    <input type="submit">
</form>

Don't build the actual form with the idea that you are using Javascript. Instead, simply hook into the page to enhance the experience.

Regularly, the above form would submit to itself. With Javascript, you can hook in and make that Submit happen through AJAX instead of a new page load.

Chacha102
I was thinking of handling dual submits (regular post if no JS, ajax if there is). I'm glad to see it's not just a kludge. Perhaps I'll make it ajax first with the noscript tags, then add in a JS-free version later.
Cuga
You'll have a lot more success, though initial dev will take longer, if you work out how to do it without the JS first. If not, you may have to hack all over the place to get it to work without AJAX.
Joseph Mastey
I can see that. Luckily we're using the Scrum process with 3 week sprints, so it's not much to continue with Ajax for now and then make tasks for converting our 5 forms or so in the next sprint.
Cuga
+1  A: 

The key here is the concept of "graceful degradation". You want to offer the best possible experience you can despite not having javascript support. For AJAX, this usually means making full page requests rather than the lovely dynamic ones we're used to; POST will similarly have to submit through HTML and load a new page.

This obviously isn't as feature-rich, and displaying it well can be a challenge, but if you're looking for a best practice, that's the goal. It's also worth telling users via a noscript tag that they have javascript disabled (some people might have legitimately done this by accident), but turning off your entire site due to a lack of javascript is not friendly behavior.

Any site worth making is worth making accessible.

Dan M
Making it so every AJAXed form on your site can also submit conventionally is A Lot Of Work. I'm convinced that these theoretical non-JS users are mostly imaginary and less real by the day. Only the oldest phones don't support JS. It's time to cut the cord.
beamrider9
There are millions of vanity sites that only function properly on one or two of the latest browsers- chances are the authors themselves will account for most of the page views, so script only is probably fine for them.The sites on the internet that have content worth viewing add script enhancements for the use and convenience of their users, not for the ease of script pasters.
kennebec
@beamrider It's certainly not always going to fit into the schedule, but I maintain that this is still something to strive for. Accessibility is an important part of modern web development, and ignoring it simply because it's inconvenient is unfair to devices like screen readers that only support very limited amounts of JS.
Dan M
A: 

Depends on the site; something like Google Maps, for example, is clearly just not going to work without Javascript. So simply showing a noscript element politely mentioning that they will need it to view the site is fine.

Probably best to avoid any patronising "you need to get a new browser" messages; they may not be able to, for a number of reasons, or may simply have chosen to install NoScript or similar. According to Mozilla, NoScript has had nearly 70 million downloads; obviously a large proportion of those will be repeat downloads for the same person, but there could easily be 10 million people out there with it installed - that's not insignificant.

"Best practice" would, I guess, be to have a gracefully degraded version if possible. Up to you to decide whether that's worth the effort or if it's appropriate for your site.

Peter