By supplying a glob that matches browsers' user agent strings , the optimizer can take into account browser specific information. E.g.
if (typeof addEventListener !== 'undefined') { myNode.addEventListener(…); } else if (typeof attachEvent !== 'undefined') { myNode.attachEvent(…); }could be optimized by taking into accout knowledge about the browser to produce
myNode.addEventListener(&hellip);on all non-IE browsers, and
myNode.attachEvent(&hellip);on IE.
To get best results, use code similar to the tests in
environment-checks.js
and if you want to avoid rechecking, store the checks in
var
s declared at the top of a function body or program:
var useGetComputedStyle = typeof addEventListener === 'undefined'; ...
This feature is experimental and should be used with care. The database of user agent info is not complete, so the merge procedure described above may have holes. And some small percentage of browsers spoof the user agent. Optimizations that assume things about the browser based on the user agent will not work.
See the wiki docs for more details.