Some people who may not be able to access (all of) Javascript:
- Blind people with non-js screenreaders
- People who actively turn off javascript
- People behind corporate firewalls
- Search engines
I am sure there are more groups that can be thought of, but these four are probably the most common who have trouble with an interface using Javascript/AJAX. And you may not care about an individual group of the list above, but there’s a big chance that one of these groups at least will fall inside the target audience of your web application. And it’s not that hard to support those people as long as you keep it in mind from the start.
The easiest approach by far is to first write your application completely without Javascript. That means your application works in most common browsers, assuming of course you have correct (X)HTML and CSS, but that is outside the scope of this post. If you have such an application running, you can easily now start expanding your application by using the graceful degradation features of symfony. These features are basically nothing more than two helper functions:
if_javascript();
//Your javascript-based code goes here
end_if_javascript();
Anything that goes between these two functions, will only be outputted if the browser supports Javascript. Easy, but what about our old code? We don’t want to have that displayed if there is Javascript support available. Well, for that, there is the good old <noscript>-tag in HTML. So, here is what your code may look like before the extending of your functionality with Javascript:
<!– Nice piece of regular HTML functionality –>
And now, here it is as extended with Javascript:
<?php
if_javascript();
//Your javascript-based code goes here
end_if_javascript();
?>
<noscript>
<!– Nice piece of regular HTML functionality –>
</noscript>
Symfony will ensure that the Javascript-based code will only be shown if Javascript is supported, and the browser will ensure that anything between <noscript>-tags will be ignored if Javascript is enabled. Powerful and easy.
Leave a Reply