Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <noscript> within <head>: Good idea or bad idea?

I noticed Facebook does this where they have a meta refresh enclosed in a <noscript> enclosed in the <head> tag. They use this to detect if the user agent has javascript enabled or not.

We were thinking of using this method for 2 reasons:

  1. To auto redirect to a non-js optimized version of the site as facebook does.
  2. To include a non-js stylesheet to hopefully disable the finger pointer over javascript only anchors as well as for CSS3 complaint browsers, fading those buttons out to make it more obvious they are disabled (not working rather).

Will using this method for the above reasons cause any adverse effects that will affect a large percentage of user agents?

like image 458
anonymous-one Avatar asked Aug 13 '11 19:08

anonymous-one


1 Answers

No, there shouldn't be any extravagantly adverse effects by using the <noscript> tag in the head.

That said, there are some disadvantages to <noscript>:

  • It only works if the browser does not support JavaScript or if it is disabled. The content of the <noscript> tag will be invisible if the Javascript is blocked by a firewall.
  • User agents with very poor Javascript support will still ignore <noscript> content.
  • While most browsers support <noscript> in the head, it is technically invalid X(HTML) so your pages might not validate.

IMO, what you are wanting to do is a very good thing, and is an appropriate use of the tag. However, an even better solution would be to use feature detection within your Javascript to enable Javascript features, rather than using <noscript> to disable them.

If you are depending on HTML5 features, I would recommend the Modernizr library for this purpose.

like image 76
Peter Olson Avatar answered Sep 23 '22 16:09

Peter Olson