Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Development Best Practices - How to Support Javascript Disabled

What is the best thing to do when a user doesn't have JavaScript enabled? What is the best way to deliver content to that kind of user? What is the best way to keep a site readable by search engines?

I can think of two ways to achieve this, but do not know what is better (or if a 3rd option is better):

  1. Rely on the meta-refresh tag to redirect users to a non-javascript version of site. Wrap the meta-refresh tag in a noscript tag so it will be ignored by those with javascript.
  2. Rely on an iframe tag located within the body tag to deliver a non-javascript version of site. Wrap the iframe tag in a a noscript tag so it will be ignored by those with javascript.

I would also appreciate high-profile examples of the correct or incorrect way to do this.

--------- ADDITION TO QUESTION -----------

Here is an example of what I have done in the past to address this: http://photocontest.highpoint.edu/

I want to make sure there aren't better ways to do this.

like image 898
Teddy Avatar asked Mar 21 '11 12:03

Teddy


5 Answers

You are talking about graceful degradation: Designing and making the site to work with javascript, then making the site still work with javascript turned off. The easiest thing to do is include the html "noscript" tag somewhere near the top of your page that gives a message saying that the site REQUIRES javascript or things won't work right. SO is a perfect example of this. Most of the buttons at the top of the screen run via javascript. Turn it off and you get a nice red banner and the drop down js effects are gone.

I prefer progressive enhancement development. Get the site working in it's entirety without javascript / flash / css3 / whatever, THEN enhance it bit by bit (still include the noscript tag) to improve the user experience. This ensures you have a fully working, readable website regardless if you're a disabled user with a screen reader or search engine, whilst providing a good user experience for users with newer browsers.

Bottom line: for any dynamically generated content (for example page elements generated via AJAX) there has to be a static page alternative where this content must be available via a standard link. If you are using javascript for tabbed content, then show all the content in a way that is consistent with the rest of the webpage.

An example is http://www.bbc.co.uk/news/ Turn off javascript and you have a full page of written content, pictures, links etc. Turn on javascript and you get scrolling news stories, tabbed content, scrolling pictures and so on.

I'm going to be naughty and post links to wikipedia:

Progressive Enhancement

Graceful Degredation

like image 57
Richard Parnaby-King Avatar answered Oct 16 '22 12:10

Richard Parnaby-King


You have another option, just load the same page but make it work for noscript users (progressive enhancement/gracefull degradation).

A simple example: You want to load content into a div with ajax, make an <a> tag linking to the full page with the new content (noscript behavior) and bind the <a> tag with jQuery to intercept clicks and load with ajax (script behavior).

$('a.ajax').click(function(){
var anchor = $(this);
$('#content').load(anchor.attr('href') + ' #content');
return false;
});
like image 25
Guillaume86 Avatar answered Oct 16 '22 13:10

Guillaume86


I'm not entirely sure if Progressive Enhancement is considered to be best practice these days but it's the approach I personally favour. In this case you write your server side code so that it functions like a standard web 1.0 web app (no JavaScript) to provide at least enough functionality for the system to work without JavaScript. You then start layering JavaScript functionality on top of this to make the system more user friendly. If done properly you should end up with a web app that at least provides enough functionality to be useful for non-JavaScript users.

A related process is known as Graceful Degradation, which works in a similar way but starts with the assumption that a user has JavaScript enabled and build in workarounds for cases where they don/t. This has a drawback, however, in that if you overlook something you can leave a non-JavaScript user without a fallback.

Progressive Enhancement example for a search page: Build your search page so that it normally just returns a HTML page of search results, but also add a flag that can be set via GET that when set, it returns XML or JSON instead. On the search page, include a script that does an AJAX request to the search page with the flag appended onto the query string and then replaces the main content of the page with the result of the AJAX call. JavaScript users get the benefit of AJAX but those without JavaScript still get a workable search page.

http://en.wikipedia.org/wiki/Progressive_enhancement

like image 44
GordonM Avatar answered Oct 16 '22 14:10

GordonM


If your application must have javascript to function then there's nothing you can do except show them a polite message in a noscript tag.

Otherwise, you should be thinking the other way around.

  1. Build your site without JS
  2. Give awesome user experience and make it full functional
  3. Add JS and make the UX even more functional. Layer the JS on top.

So if the user doesn't have JS, your site will still revert to step two of your site state.

As for crawling. If your site depends on AJAX and a lot of JS to work, you can make gogole aware of it : http://code.google.com/web/ajaxcrawling/docs/getting-started.html

like image 1
JohnP Avatar answered Oct 16 '22 13:10

JohnP


One quick tip that may help you: just install lynx, a command-line web browser, and you'll immediately see how google and other seo see your site (and blind people too). This is very useful. Of course, in a command line windows, there's no graphics and javascript is disabled.

like image 1
Olivier Pons Avatar answered Oct 16 '22 14:10

Olivier Pons