Shouldn't we use <noscript> element?

Viewed 75009

I found some good cons here:

  • The noscript element only detects whether the browser has JavaScript enabled or not. If JavaScript is disabled in the Firewall rather than in the browser then the JavaScript will not run and the content of the noscript element will not be displayed.

  • Many scripts are dependent on a specific feature or features of the language being supported in order for them to be able to run (for example document.getElementById). Where the required features are not supported the JavaScript is unable to run but since JavaScript itself is supported the noscript content will not be displayed.

  • The most useful place to use the noscript element is in the head of the page where it would be able to selectively determine what stylesheet and meta elements get applied to the page as the page is loading rather than having to wait until the page is loaded. Unfortunately the noscript element is only valid within the body of the page and so cannot be used in the head.

  • The noscript element is a block level element and therefore can only be used to display entire blocks of content when JavaScript is disabled. It cannot be used inline.

  • Ideally, web pages should use HTML for the content, CSS for the appearance, and JavaScript for the behavior. Using the noscript element is applying a behavior from within the HTML rather than applying it from JavaScript.

Source: http://javascript.about.com/od/reference/a/noscriptnomore.htm

I very much agree on last point. Is there a way to make and add an external <noscript> file? Should we place <noscript> in the <head>?

11 Answers

It's better to have the default be non-javascript, and then let a javascript code overwrite with a javascript enabled page. Doesn't have to be much. Can just be a display:none; block, which is then set to display:block; by javascript, and vice versa for the non-js page.

In the (hopefully near) future you will be able to use css @media scripting:

@media (scripting: none) {
    /* styles for when JS is disabled */
}

Like all things, use the right tool for the job.

If you are using Google Maps API, you have a static image via tag and that gets replaced with dynamic JS map. Google have recently started charging for everything thus with the above example it's going to cost you twice, once for static and once for dynamic. The static map is only relevant if JS is disabled. Therefore to save double paying it seems to me the best solution is to wrap the tag for the static map in a tag.

The "noscript" element is not supported in XML or in XHTML5 polyglot, so not recommended by the W3C.

I also do not like the idea that every page starts out with a no-script viewable div that is then hidden by some Javascripted circus trick on every page of a website. Dangerous and more scripting dependencies that could fail or wreak havoc if changed by a later developer.

A better strategy is to design your site with a basic html design that wraps around all inner scripted content so the user at least sees a page design with a header and a place where basic content would appear. If its empty its pretty obvious they cannot view the content for a reason. I would then add a tiny message or information icon in the footer saying, if you see no content your javascript is disabled. That appears whether they see scripted content or not. This solution is scripting free.

As a last resort you could have that message be hidden by scripts using display:none at the bottom of every web page.

It's not as sexy as providing alternate content or a message box, but in the case of heavy Angular websites you would have to create a new content page for them anyway should scripting be disabled. This solution also accounts for no script support in a user-agent versus disabled support, and makes your web page 100% XML and HTML5 compatible with all user agents by avoiding the noscript tag.

Related