SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    Matt Williams revsorg's Avatar
    Join Date
    Jun 2002
    Location
    Planet Vorcon-5 in sector cx-37-b
    Posts
    1,136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    White space and comments in (X)HTML

    I was at a meeting the other day when someone who I believe knew what he was talking about said that latest thinking is that white space within (X)HTML should be removed in order to maximise accessibility, and there should be no comments.

    This W3 document seems to shed some light on it, but if anyone can make an informed comment I would be very grateful.
    work: revs | ecru
    reviews: films | mp3s
    projects: Glastonbury Tor | London IT support

  2. #2
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Avoid this if you can. White space is essential to readability of the code (as is proper formatting/indenting). If I can't read the code, I won't bother with it (unless it's in the forums and someone's asking for help, then I'll gripe and groan about how hard it is to read, and format it myself).

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,824
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Whitespace and comments anywhere that a single space is allowed should have no impact whatsoever except a very slight difference to load times that hardly anyone will notice unless you have millions of spaces.

    Whitespace where no whitespace is wanted at all can break things where the display type is inline but will have no effect whatever when the display type is block.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How in the world could whitespace nodes and comment nodes affect accessibility?

    OK, if you have a million lines of comments it will take a long time to download for a low-bandwidth user, but it doesn't prevent access.
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    Toronto, Ontario
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    How in the world could whitespace nodes and comment nodes affect accessibility?

    OK, if you have a million lines of comments it will take a long time to download for a low-bandwidth user, but it doesn't prevent access.
    I think this is about the code itself. Think about the blind programmer who has to go through tones of whitespace in order to get to the next line of code.

    Its the accessibility/usability for the developer and not necessarily for the user.

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would assume that source code entirely devoid of comments would be just as big an obstacle for a blind user (plus all sighted users), unless the code is very, very trivial.

    Whitespace shouldn't be a problem, either. Any editor worth having will have key commands to jump to the next non-blank character.
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about having a php script that buffers the output. Then just before everything is output, preg_replace all line breaks and tabs to make the code all on one line. In the servers script the code will be easy to read, but when output it will be small, save bandwidth and be faster to download if the code is very long.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  8. #8
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because some people will try to learn how the Web site was built by looking at the HTML source code and the stylesheet.

  9. #9
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    What about having a php script that buffers the output. Then just before everything is output, preg_replace all line breaks and tabs to make the code all on one line.
    That will wreak havoc with any PRE element or boxes whose white-space property is something other than normal.
    Birnam wood is come to Dunsinane

  10. #10
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That too.

  11. #11
    SitePoint Addict CaryD's Avatar
    Join Date
    Nov 2006
    Location
    San Diego, CA
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by revsorg View Post
    I was at a meeting the other day when someone who...said that latest thinking is that white space within (X)HTML should be removed in order to maximise accessibility, and there should be no comments.
    Perhaps he meant you shouldn't comment things when they aren't comments? For instance, in XHTML you shouldn't place embedded styles and scripts within comments.

  12. #12
    Matt Williams revsorg's Avatar
    Join Date
    Jun 2002
    Location
    Planet Vorcon-5 in sector cx-37-b
    Posts
    1,136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was a Stellent content managed website that he had been making AAA accessible, and these were two aspects of "latest thinking about accessibility" that they had incorporated into their project, systematically stripping them (comments and whitespace) out of the code that is delivered to website visitors.
    work: revs | ecru
    reviews: films | mp3s
    projects: Glastonbury Tor | London IT support

  13. #13
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Schulz View Post
    Because some people will try to learn how the Web site was built by looking at the HTML source code and the stylesheet.
    For a current project of mine the production code will be compressed as much as possible, but I'm releasing the source code (HTML, CSS, PHP) to the public, fully documented all whitespace preserved.

    So if they want to learn how my site was put together they may download the full source files.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  14. #14
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by revsorg View Post
    It was a Stellent content managed website that he had been making AAA accessible
    I'd love to see a link to it. I've only seen a handful of AAA-compliant websites, and I've never managed to create one myself.

    I've seen tons of websites that claim to be AAA, though, just because Bobby or Cynthia says so.
    Birnam wood is come to Dunsinane

  15. #15
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    It'd also be interesting to see what the point in the AAA-checklist, stripping of whitespace falls under.

    Besides, AAA-accessibility requires that the page is available in every language in the world, including languages invented by the visitor (see point 11.3), effectively making AAA-accessibility impossible.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  16. #16
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by revsorg View Post
    two aspects of "latest thinking about accessibility" that they had incorporated into their project, systematically stripping them (comments and whitespace) out of the code that is delivered to website visitors.
    hah...latest thinking...where? i never heard of it, and it sounds quite misguided.
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  17. #17
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    NL, Rotterdam
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Add me to the curious ppl that wonder how to catch up to the 'latest thinking about accessibility'.

    I can't imagine how comments and white spaces (they mean white line perhaps) could hinder accessibility, besides secondary effects like increased download-time...

  18. #18
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also can't really see how whitespace would effect accessibility.

    I have run into the problem of having embedded scripts cause perfectly valid code not to validate. However, that is simply an issue of the validator not handling javascript.

    If whitespace was removed from all the code it would make every developer's day a long one. Whitespace, comments, and proper indenting are there for readability. In my mind, readability to a developer is almost as important as accessibility to the user - especially when they can work hand-in-hand (IE not one or the other)
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  19. #19
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeanco View Post
    I have run into the problem of having embedded scripts cause perfectly valid code not to validate.
    Why are you using document.write() with XHTML? That doesn't work.
    Birnam wood is come to Dunsinane

  20. #20
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    Why are you using document.write() with XHTML? That doesn't work.
    Thats news to me. I just spent a bit of time digging around to verify that person's blog entry - as it seems most searches on the subject just linked to what you linked to. For others in the same boat, there is a w3 issued page here: http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite that supports the argument.

    My article was based on the FAQ entry I was sent to by the validator when I was going through the code. Now that I know this, I'll be working on fixing this code and will update that article accordingly when its done.

    Thanks for the heads up.
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  21. #21
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Location
    Montreal, QC, Canada
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by revsorg View Post
    I was at a meeting the other day when someone who I believe knew what he was talking about said that latest thinking is that white space within (X)HTML should be removed in order to maximise accessibility, and there should be no comments.

    This W3 document seems to shed some light on it, but if anyone can make an informed comment I would be very grateful.
    It sounds more like something to minimize file size.
    D.: Web Developer | Designer | Management Consultant
    // Writing daily on:
    netParticles: Web Promotion and Marketing Blog | Twitter | RSS
    (insightful and helpful. not some know-it-all SEO site with spam text)

  22. #22
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Netherlands
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With dynamic sites you hardly ever see the html source properly formatted and indented, unless the end document has been put through something like html tidy.
    Go visit my site :-D you know you want to ;-)
    www.mech7.net

  23. #23
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pixelsoul View Post
    With dynamic sites you hardly ever see the html source properly formatted and indented, unless the end document has been put through something like html tidy.
    I always make sure this is the case when making dynamic sites, since it makes error searching that much easier.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •