Feature detection (web development): Difference between revisions

Content deleted Content added
m Added sources
m Corrected date format from previous edit
Line 3:
{{unreferenced|date=March 2014}}
 
'''Feature detection''' (also '''feature testing''') is a technique used in [[web development]] for handling differences between [[runtime environments]] (typically [[web browsers]] or [[user agents]]), by programmatically testing for clues that the environment may or may not offer certain functionality. This information is then used to make the application adapt in some way to suit the environment: to make use of certain [[API]]s, or tailor for a better user experience.<ref name=":0">{{Cite book |last=Meiert |first=Jens |title=The Web Development Glossary |publisher=Frontend Dogma |year=202014 July 2021 |language=eng}}</ref>
 
Its proponents claim it is more reliable and future-proof than other techniques like [[User agent#User agent sniffing|user agent sniffing]] and browser-specific CSS hacks.<ref name=":0" />
Line 9:
==Techniques==
 
A feature test can take many forms. It is essentially ''any'' snippet of code which gives some level of confidence that a required feature is indeed supported. However, in contrast to other techniques, feature detection usually focuses on performing actions which directly relate to the feature to be detected, rather than [[heuristics]].<ref>{{Cite web |title=Implementing feature detection |url=https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Feature_detection |url-status=live |access-date=Aug 23, August 2022 |website=mdn web docs}}</ref>
 
As [[JavaScript]] is the most prevalent [[scripting language]] in web browsers{{Citation needed|date=March 2014}}, many feature detection techniques use JavaScript to inspect the [[Document Object Model|DOM]] and local JavaScript environment.