JavaScript : pros and cons
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: JavaScript : pros and cons

  1. #1
    Senior Member Spekter1080's Avatar
    Join Date
    Oct 2005
    Location
    Iowa
    Posts
    101

    JavaScript : pros and cons

    From what i've seen and heard, JavaScript doesn't look like a good language to use when building a professional site. I know that its strength is for client-side purposes, but is it really safe, or even worth using? Also, if you'd like, could you post any links to examples of good uses for JavaScript? (um, by the way, i'm speaking in a theoretical manner, i don't have any specific applications or examples at the time of this posting for JavaScript) Thanks again
    there's always a way in...

  2. #2
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    It's fine. Safer now than ever, since most ways for JS to interact with the OS have now been prevented. It's the only clientside scripting language to make HTML/CSS in any way dynamic. CSS can now do a very few things that you used to need JS for, but just a few.

    Most of the criticisms of using JS are not quite accurate. For instance, while it's true that if you use JS to say...write a dynamic menu to your page on the fly, it'll hurt your SEO and make the page inaccessible to audio browsers, it's also possible to write a JS/CSS dynamic navigation menu that in no way harms the SEO, and is completely accessible to audio browsers as well.

    The figures say about 1 in 10 users have JS disabled, but my view of that is if you disable a technology in wide use, then you must accept the limitations it imposes on you. In other words, that's your problem, not the web builder's. And while audio browsers don't have much JS support, they run IN your current browser, which probably does.

  3. #3
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    I'm a little crustier. My rule of thumb (which is, of course, violated as necessary) is that the basics must work without javascript. Sure, you might skip animations, nice progress bars, fades, and all that jazz. That's fine. But the site must be navigable with it off. For instance, a fly-out menu, if it doesn't expand because of javascript, must have it's main button clickable so that you can still advance and see the rest of the options.

    Here's a tip that may help if you want a nice site but also compatibility. Write the site so that it's basics work. And then use javascript to modify the page itself (Document Object Model) in order to make everything nice.

    For instance, consider popup windows. You want the link to open in a new window. The HTML-spec way is basically this:
    Code:
    <a href='page2.htm' target='_blank'>Click!</a>
    Of course, you want to open it with Javascript and size the window and turn off the titlebar and all that, right? Normally, you'd add an onclick event, but then you might have two windows popping up. Instead (and I apologize I'm too lazy to write example code) you should be able to:
    • Add a class='jpopup' attribute to the <a> tag
    • Use javascript to search through the document and find all of those tags
    • For each tag, store the href value somewhere, and remove or change the actual href value of the link to "#"
    • Before going to the next tag, attack an onclick event to the link using the url you stored from before.


    If they do have javascript, the javascript rewrites the page to behave in the nicer way. If you don't, then everything is still usable, albeit uglier.
    [HvC]Terr: L33T Technical Proficiency

  4. #4
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    It's a minor point and one of personal choice, but the way I would code a flyout menu would still be accessible to an audio browser, so no sight-challenged viewers would be omitted. But those that choose to disable JS of their own volition, them I'm not worried about. Like I said, you make a choice to disable a widely used technology, you live with the consequences. That said it's probably better to use a CSS based flyout menu anyway

  5. #5
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    There's also an easier way of dealing with this. You make an HTML only page, and a JS version. The HTML only page contains a JS redirect to the JS page. If they don't have it, the redirect does nothing. If they do, they get the JS page.

  6. #6
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    But then you need to keep two seperate pages in sync in terms of their content and all that. If you use JS to rewrite the page on the fly, you just need to ensure the right class or ID values are placed inside, and you save effort because you can automate many tedious changes, like with the popup links.
    [HvC]Terr: L33T Technical Proficiency

  7. #7
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    But how would that affect SEO? Or would it not affect it at all?

  8. #8
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    I doubt search engine spiders execute javascript in the pages they visit--too much potential ambiguity, security concerns, and processing power issues... In which case designing by default for people without javascript is likely to improve your site's crawlability. <a href=''> is always going to be a lot better recognized than <a onclick=''>. Probably the only JS any good spiders would recognize is a direct window.open() anyway, which means you're not going to be covered if you use your own "myPopupOpen()" function or something.

    Now, it's possible my premise is wrong, and most browsers will not be confused when they encounter an
    <a href='...' target='_blank' onclick='js();'>
    situation. But when it comes to stylesheets and mouse-over events (:hover vs. onmouseover) it's still a paradigm to keep handy--that you can use javascript to rewrite the page itself with the DOM model in order to smooth over or bypass incompatibilities between your basic and fancy versions.

    P.S.: Just tested: Major browsers DO open two windows if they have javascript on and see both onclick and a href+target='_blank'
    Last edited by Terr; January 3rd, 2007 at 02:27 AM.
    [HvC]Terr: L33T Technical Proficiency

  9. #9
    Senior Member JPnyc's Avatar
    Join Date
    Jan 2005
    Posts
    2,734
    I think spiders just crawl what they understand, so they wouldn't be bothered by an onclick event. They'll just look for what they're programmed to look for.

  10. #10
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    But if they don't see that onclick, then you've just closed off part of your site from search engines. (Which if intentional is better done by robots.txt and user-agent restrictions.)

    They will crawl less of your site. If all you had were, say, screenshots, then I suppose it's no big loss, but if you use javascript popups (and only javascript) for pages with important keywords on them, then JS is a strike against your site. I'm not saying JS will "bother" the spiders in a negative way, but in terms of "attention" you want to bother spiders--you don't want to wall off important parts of your site so that only the homepage is accessible, etc.
    [HvC]Terr: L33T Technical Proficiency

Posting Permissions

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