开发者

JavaScript over/under usage. what is acceptable these days?

As a budding web developer I'm trying to walk the fine line of cross-platform usability/compatibility and pizazz(functionality).

Is this as much of a problem as it was a few years ago? The parts of my site that - dare I say - require (aka make my life easier) JavaScript would not be something that a mobile would want to access (although it could if it wanted to).

http://www.w3schools.com/browsers/browsers_stats.asp

If you scroll down, it seems to indicate that 95% of computers accessing that site have JavaScript enabled/installed.

Any input from some开发者_开发百科one who has dealt with this issue would be appreciated.


I don't know anyone these days who has Javascript turned off permanently. The sheer amount of sites that rely on JS means that the web is virtually unusable without it.

The vast majority of people simply leave it on all the time. Most of the really serious security holes that used to make people turn it off have long since been fixed, so it's much less of an issue than it used to be.

There are still some things that worry the paranoid, but even then most people who do disable JS do so on a site-by-site basis using a tool like the Firefox NoScript extension rather than just switching it off. When these people visit a new site, they have to decide whether they trust it enough to enable JS for it.

The other demographic which may be affected is disabled users, using a screen reader or other assistive technology. Many of these people may not be able to use Javascript. (that said though, many of them can; screen readers are not nearly as backward compared with regular browsers as many people imagine)

As the end of the day though, it's up to you really to decide what to do about supporting your visitors who don't have JS. Here are some things to consider:

  • Does your site absolutely require Javacript - If you're writing a GMail type system, and the whole thing only works because of JS, then obviously you can't support not having it.
  • How much of your audience will have JS disabled? How many of them will be prepared to re-enable it just to visit your site? How many of those people are you prepared to lose? You'll need to know your own demographic before you can answer that.
  • Can you write the JS features such that the site still works sufficiently without them? Users with JS turned off will expect sites they visit not to look great and having missing functionality, but they'll be happy as long as the important bits still work for them.


It depends on what you're doing. I'm a firm believer in Javascript gracefully degrading if it's just adding UI sugar. It's a fine line though, and there's not really one answer. Sometimes you'll be able to make assumptions about about your userbase -- for example, if you're writing a mobile web application, you're pretty much guaranteed good HTML5 support. Other times, you might need to worry about having rock-solid IE6 support. It all comes down to what your audience is and how much time you can afford to spend supporting different configurations.

I would highly recommend that you, as a budding web developer, learn how to do progressive enhancement with your Javascript. It's often the "right" way to approach a problem, even if you don't care about supporting javascript-less browsers; and it's very likely that you'll run into a situation in the future where you've got to support backwards browsers (which is a group you can lump Googlebot into as well).


w3Schools is used by developers and is not a realistic representation of the general public.

Global Stats Counter (http://gs.statcounter.com/) is a more valid measure of general users.

How you code your site depends on your expected audience.


I don't think that number is going to change drastically - 95% is close to correct.

My suggestion would be to substitute JQuery as much as possible, as it will help mitigate browser specific issues. Also, plan on adding NoScript functionality so that if your user doesn't have JS, it will degrade gracefully to something with less "Pizzaz"

As far as mobiles accessing pages containing JS - don't be too worried about that, mobile browsers can process javascript just fine.


As said by others, this depends on your audience. Furthermore, your site should have some baseline functionality. That is, they should be able to view and use your content with just about anything. Any extras can apply for those that can view it.

The majority of users do have Javascript enabled, but sometimes it doesn't work due to malware, script blockers, ad blockers, etc. These people are used to things not working. (Try viewing YouTube and a few other popular sites without Javascript enabled.) That doesn't mean you can ignore them. It simply means that majority of your site should function without incident without Javascript.


As long as your site fails "gracefully" you can really just choose for yourself how much of the populace you want to try and accommodate.

Most of the sites I do, do not make sense to have even minimal functionality without javascript since the very reason they are there is to purchase/browse mySQL content.

So, I just make sure that if they need javascript, I check for it as soon as the page loads and if it is not present, I let the user know nicely, that they will need to enable or install it in order for my site to function properly.

Of course, in an ideal world you should always accommodate every segment of user, but since clients rarely want to pay for that kind of development, I usually end up just trying to catch the biggest segment I can for the least amount of resources and development.

Here is the code I like to use:

<!-- make sure javascript is turned on.. --><noscript><div style="position:absolute;top:10px;left:10px;width:300px;height:90px;background-color:#FFF;border:solid;border-width:2px;border-color:#F00;font-size:14px;text-align:center;overflow:hidden;z-index:999;"><div style="position:absolute;top:5px;left:5px;width:50px;height:80px;background-color:#F00;color:#FFF;font-size:48px;text-align:center;line-height:80px;">!</div><div style="width:230px;height:60px;position:absolute;top:15px;left:65px;text-align:center;font-size:13px;color:#F00;font-style:italic;">ERROR: JAVASCRIPT MISSING<br /><br />Enable or install Javascript<br />to view this site.</div></div></noscript>

This has worked well for me in all the browsers I have tested it in.


I like that you've asked the question, but I have to say that I've been very disappointed by the answers you've received so far (including the answer that was accepted). There seems to be a general perception that users who have JavaScript disabled are either Luddites or idiots. There has been a lot of talk of "graceful degradation", and that's missing the point altogether. The point is accessibility.

Unless you are building a site that would offer nothing to a user with visual or motor impairments (like, say, an on-line graphical game), your site should just plain work and make perfect sense with CSS, images and JavaScript all disabled. Low-vision users will probably have your CSS overridden so thay can read the sceen, and they won't care about your images much unless the alt text (and longdesc, if you've bothered to include it) makes it sound compelling enough to bother looking at an enlarged version. And the blind will be using either a Braille interface or a screen reader like JAWS, neither of which is particularly compatible with background updates on random areas of the page.

Now, before anybody goes off on a tear about how difficult it would be to design for the disabled, let me say that this is the easy part. Designing the basic, working application is all about paying attention to the document structure (semantic tagging and so forth), and if you've been paying attention to the document structure, the chances are pretty good that you've also paid some attention to the data structure back on the server. At this point, the app may not look like much, but it will provide all of the information it's supposed to provide and will take any input it needs to from the user. Sure, everything requires complete page loads, but it all works.

Images, CSS and JavaScript can all be used to enhance that working application. The object of the game is not "graceful degradation", but "progressive enhancement". Images and CSS not only add decoration, they can reinforce the information hierarchy and clarify user actions for users who are equipped to appreciate the visual enhancements. JavaScript can override the default behaviour of UI elements (links, buttons, textareas and so on), providing immediate feedback to the user and maintaining an uninterrupted workflow. Providing AJAX-friendly APIs to the same data structures you've used for the vanilla HTML app's pages is not at all difficult.

There are no excuses for failing to pay attention to accessibility. There are only ignorance and bigotry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜