HTML and CSS Reference
In-Depth Information
just for the curious, it's worth popping the hood on Modernizr
as it's a great way to learn how some features can be detected.
Yo u m i g h t i n d t h a t s o m e p l a c e s a r e u g l y t o l o o k a t a s b r o w s e r s
sometimes lie about their support or don't completely follow
the specifications.
Performance of feature
testing and polyfills
A question that's usually asked when JavaScript is proposed to
solve a deficiency in the browser is: “What's the performance?”
Of course, any additional JavaScript that runs in the browser
(even if it's just a one-liner that tests for the presence of a par-
ticular feature) will have a performance impact. However, when it
comes to real-world use, a very large proportion of feature detec-
tion tests are going to be micro-snippets of code that won't have
any effect on your application at all. Runtime will be in the milli-
seconds, which we'd say is negligible in most situations.
What you should also remember is that JavaScript engines are
really fast. As the newer and faster browsers are less likely to
need polyfills, extensive patches, or helper scripts—and instead
require only that you run a few tests—there will be little or no
cost for users with modern browsers.
Even for older browsers, which have slower JavaScript engines,
there will still be no significant cost in the feature detection, but
there may be some wait time to load the polyfill. This may be
unavoidable, as we're trying to drag these old browsers into
today's world, albeit kicking and screaming.
What's particularly important is that you don't polyfill everything
including the kitchen sink (sorry, I couldn't resist the poor man's
DIY joke). When you're including JavaScript to do what the
browser can't do natively, it will always cost a little bit of perfor-
mance. If you include a lot of redundant functionality that you
won't make use of, then it's obviously a waste. Try to include
only what you absolutely need. If you're building the next Super
Bruce & Super Remy adventure game using canvas, and find
that polyfilling slows IE6 down to a grinding halt and your main
audience is IE6 users: don't use it! As the developer you need to
make the judgment call as to whether the selected technology
is the right tool for the job.
Search WWH ::

Custom Search