Java Reference
In-Depth Information
Shims and Polyfills
HTML5 APIs progress at a rapid rate―new APIs are constantly being introduced and exist-
ing APIs often change. Modern browsers are very quick to update and implement many of
the changes, but you can't always guarantee that users will have the most up-to-date browser.
This is where a shim or a polyfill comes in handy. These are libraries of code that allow you
to use the APIs as usual; they then fill in the necessary code that not provided natively by
the user's browser.
The terms shim and polyfill are often used interchangeably. The main difference between
them is that a shim is a piece of code that adds some missing functionality to a browser, al-
though the implementation method may be differ slightly from the standard API. A polyfill
is a shim that achieves the same functionality while also using the API commands that would
be used if the feature was supported natively.
This means that as a ninja developer, your code can use the APIs as normal and it should
work as expected in older browsers. The advantage here is that the same set of standard API
commands can be used―you don't need to write additional code to deal with different levels
of support. And when users update their browsers, the transition will be seamless as their
experience will remain the same. Once you are confident that enough users have up-to-date
browsers, you can remove the polyfill code without having to update any actual JavaScript
code.
A comprehensive list of shims and polyfills is maintained by the Modernizr team.
Search WWH ::




Custom Search