Javascript graceful degradation in symfony 1.0

Even though in this day and age of Javascript, most people do not really think about this anymore, it can still be important to have your site working when someone either has no javascript or has it turned off. It does happen, so you better think about it a bit. Symfony has some neat features for graceful degradation.

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.


Add comment

Comments

gravatar jack: Another option: use javascript to hide any functionality that is only there for non-javascript-enabled users. This takes away the need for the extra markup of the noscript tag. Could be a matter of personal preference/project specs, though.
May 20, 2008
gravatar The Daily Herald: In the present time it is important to know about languages in order to move forward in the field of IT. Thanks for providing info about this topic here. Keep it up
May 30, 2011
gravatar place to know about business status: It is a good addition for all those who are behind the firewalls. Good sharing from your side. But you must try to mention it's procedure, as it will be good enough for all of us.
June 16, 2011
gravatar classifieds homes los angeles: Symfony really has some features for graceful degradation.mostly peoples like these features.i like your post you do good effort to make it more valuable.
thanks for sharing.
July 4, 2011
gravatar florida spray foam insulation: There is nothing better then using javascript. I think the options are endless for this. There is nothing better then this.
October 28, 2011
gravatar goose jackets: thanks a lot,best regards!
December 20, 2011
gravatar lqeswck: It is a good addition for all those who are behind the firewalls. Good sharing from your side. But you must try to mention it's procedure, as it will be good enough for all of us.

December 23, 2011
gravatar Toyota Cars: Interesting topic what you have shared with us. Your writing skill is really very appreciative. I love when you share your views through the best articles.Keep sharing and posting articles like these.This article has helped me a lot.Keep posting this stuff.

January 21, 2012
gravatar coach outlet online: If you buy Coach items at the
coach outlet online

store, the goods will be sent out within 24 hours after confirming your payment and arrive to your door within 7 work days.No one can deny the shopping at the
coach factory outlet

is satisfactory. For the low prices and good quality.
January 29, 2012
gravatar coach outlet: coach outlet

handbags You can not just save your cash but also your time inside a convenient way to obtain the exact same bags product and do not be concerned the shippment of one's products.The
coach outlet store online

are utilized for formal event in company area that will display your excellent taste.Not only does a briefcase make is easier to carry things.
January 29, 2012
gravatar discount uggs boots: I am typically to running a blog and i really respect your content. The article has really peaks my interest. :!:
February 1, 2012
gravatar michael michael kors: Really appreciate this wonderful post that you have provided for us. Great site and a great topic as well i really get amazed to read this.

February 2, 2012
gravatar Supporting Providers: Unmake is everything, so we pauperism to subvent that there are values on what we are clinical to protect our subscribers hypnotised. Sue them nettled is one belief we moldiness enounce do!

February 3, 2012
gravatar Diamond Sofa: I really liked reading your post!. Quallity content. With such a valuable blog i believe you deserve to be ranking even higher in the search engines
February 7, 2012
gravatar ashley furniture: You write Formidable articles,keep up good work.
February 7, 2012
gravatar caplan syndrome: Really appreciate this wonderful post that you have provided for us. Great site and a great topic as well i really get amazed to read this.
February 8, 2012
gravatar How to Select House Plans: Interesting topic what you have shared with us. Your writing skill is really very appreciative. I love when you share your views through the best articles.Keep sharing and posting articles like these.This article has helped me a lot.Keep posting this stuff.


February 9, 2012

Php5_zce_logo

Upcoming events

I will be speaking 17-02-2012: Techademy Trainingday February
I will be speaking 23-02-2012: Zend Webinar: Git for Subversion Users

Tags

1337 2008 2010 2011 4developers access modifiers accessibility AdaLovelaceDay09 advent agavi agile alfred amsterdam apache api apple article articles atk atkMetaNode audioscrobbler automation azure backwards compatibility barcelona barcodes bash bbc bbq beatstad belgium best practices bittorrent blogging blogs boards of canada book books bughuntday bundle caching cake cal evans calendar career cat cerf certificate cfp clear cms cologne common sense communities community components conference conferences contest continuous integration contribute contribution crisis css custom d-day datetime DbFinderPlugin decorator decorators deployment devdays development directoryindex docblox doctrine documentation download dpc dpc09 dpc10 dpc11 DPC2008 dreamhost drupal dv7 eclipse ed editors efficiency enterprise errors event events expertise ezcomponents facebook finland flickr fork framework frameworks freelance freeze frontend fun game games geoip germany getting real git github gnome-do google google calendar googletalk graceful degradation hack hackers hidden gem hiphop howto hp HR html http i386 ibuildings icann ide ideasofmarch idm imovie indy ingewikkeld integration international php conference internet interview ipad IPC ipc ipc08 ipc10 ipc11se iterm2 javascript jenkins jenkins-php job job openings jobeet john peel joomla joomladays kiva kubuntu launcher launchy left on the web libraries library lighttpd lime linktuesday linux live london loudblog m2ts mac magazines malware mambo marjolein mediterra meeting meme meta methodology micro-financing microframework microsoft migration movie music mysql namespace namespaces netbeans netherlands newsfire nllgg nos odmarco open source opinion ORM osx paradiso paris partnership pavilion pear pecl performance personal pfc10 pfc11 pfcongres pfcongrez pfz photo php php5.3 phpabstract phpazure phpBB phpbb phpbelgium phpbenelux phpbnl10 phpday phpdoc phpdocumentor phpgg phpitalia phpnw phpnw08 phpnw11 phpstorm phptek phptek09 phpuk2009 phpUnderControl phpunit php|architect php|tek podcast politics portability postcrossing presentation presentations private projects protected prototype PSR-0 public python qa qr codes re2c recruiting refactoring review rewrite ruby on rails san francisco schedule scifi script security sensio seven things sfdaycgn sflive2011 shell scripting silex simplexml slides smfony software sogeti solar sound speakers spl ssh standard standards star trek static steer strings stylesheets subversion symfony symfony live Symfony2 symfonycamp symfonyday symfonylive symfonyUnderControlPlugin talk talks techademy technology techportal tek09 telecommuting terratec terrorism testfest testing textmate textpattern the right tool timeout tips tld todo tomas tools training twig uncon unet usability usergroup validation vhost video vim vinyl virus warp webinar weblogging webservices wiki windows winphp women wordpress work workshop world world of warcraft wpi writing wunderlist xml xpath xsd yara year youtube zc11 ZCE zemanta zend zend framework zend server zend studio zendcon Zend_Form zite
© 2004 - 2012 Stefan Koopmanschap + Powered by Symfony, photos powered by Flickr, links powered by Delicious, Shanghai smilies by Iconbuffet. Feeds: rss / atom. Left on the Web v4.4.0.1