0 added
0 removed
Original
2026-01-01
Modified
2026-02-21
1
<p>DOM is continuously evolving. Some browsers adapt to it faster than others, so using the latest innovations is not always easy. Each time developers should think about which browsers future customers most frequently use.</p>
1
<p>DOM is continuously evolving. Some browsers adapt to it faster than others, so using the latest innovations is not always easy. Each time developers should think about which browsers future customers most frequently use.</p>
2
<p>Developers usually use analytics to find out which browsers are more popular. An example is Google Analytics, which collects data in real-time from everyone who visits the site.</p>
2
<p>Developers usually use analytics to find out which browsers are more popular. An example is Google Analytics, which collects data in real-time from everyone who visits the site.</p>
3
<p>In some particularly complex situations, you may need to support old browsers that can barely do anything. It is often the case for government organizations.</p>
3
<p>In some particularly complex situations, you may need to support old browsers that can barely do anything. It is often the case for government organizations.</p>
4
<p>For example, let's observe a method called matches() that searches for elements by CSS selectors. Internet Explorer supports it, but only as of version 9. If your project claims to be compatible with IE8, then there'll be an error if you call this method:</p>
4
<p>For example, let's observe a method called matches() that searches for elements by CSS selectors. Internet Explorer supports it, but only as of version 9. If your project claims to be compatible with IE8, then there'll be an error if you call this method:</p>
5
<p>Fortunately, the nature of JavaScript means you can partially compensate for the shortcomings of older browsers. Thanks to prototypes, developers still have an opportunity to add missing functionality directly to the DOM implementation. We can do it using polyfills.</p>
5
<p>Fortunately, the nature of JavaScript means you can partially compensate for the shortcomings of older browsers. Thanks to prototypes, developers still have an opportunity to add missing functionality directly to the DOM implementation. We can do it using polyfills.</p>
6
<p>The general principle of operation for these libraries is as follows:</p>
6
<p>The general principle of operation for these libraries is as follows:</p>
7
<ol><li>Check if the desired method or property is available</li>
7
<ol><li>Check if the desired method or property is available</li>
8
<li>If it isn't there, then add it</li>
8
<li>If it isn't there, then add it</li>
9
</ol><p>We should load the library with polyfills before executing any other code. Only then will the rest of the code be able to count on the presence of the necessary properties. f the code be able to count on the presence of the necessary properties.</p>
9
</ol><p>We should load the library with polyfills before executing any other code. Only then will the rest of the code be able to count on the presence of the necessary properties. f the code be able to count on the presence of the necessary properties.</p>
10
<h2>Adding a method</h2>
10
<h2>Adding a method</h2>
11
<p>Below is an example of a polyfill for the node.matches() method. This polyfill works for all popular browsers and uses their specific features. You can see by the names of the properties:</p>
11
<p>Below is an example of a polyfill for the node.matches() method. This polyfill works for all popular browsers and uses their specific features. You can see by the names of the properties:</p>
12
<p>After executing this code, you can use the element.matches() method without worrying about it not existing in older browsers.</p>
12
<p>After executing this code, you can use the element.matches() method without worrying about it not existing in older browsers.</p>
13
<h2>Adding a property</h2>
13
<h2>Adding a property</h2>
14
<p>Let's discuss a more complex option that involves adding the ParentNode.lastElementChild. In this case, you have to program the logic for searching for the desired element:</p>
14
<p>Let's discuss a more complex option that involves adding the ParentNode.lastElementChild. In this case, you have to program the logic for searching for the desired element:</p>
15
<p>The examples above are incomplete. If you look at the sources of the corresponding libraries, you'll want to close them away. The amount of code is beyond decency. Ensuring it works the same way in all browsers and all their versions is challenging.</p>
15
<p>The examples above are incomplete. If you look at the sources of the corresponding libraries, you'll want to close them away. The amount of code is beyond decency. Ensuring it works the same way in all browsers and all their versions is challenging.</p>
16
<p>There's an excellent resource<a>CanIUse</a>, which helps to learn about the support for specific features in different browsers:</p>
16
<p>There's an excellent resource<a>CanIUse</a>, which helps to learn about the support for specific features in different browsers:</p>
17
<p>And the easiest way to add polyfills to your website is to use the<a>polyfill.io</a>project. In addition to this project, GitHub has many ready-made polyfills for all parts of the DOM. They scatter across repositories belonging to different people, so if you need to add a polyfill to something, you'll first have to spend time searching for the library.</p>
17
<p>And the easiest way to add polyfills to your website is to use the<a>polyfill.io</a>project. In addition to this project, GitHub has many ready-made polyfills for all parts of the DOM. They scatter across repositories belonging to different people, so if you need to add a polyfill to something, you'll first have to spend time searching for the library.</p>
18
<p>Sometimes, you check for a feature and decide what code to execute. In this kind of situation, the modernizr library will help:</p>
18
<p>Sometimes, you check for a feature and decide what code to execute. In this kind of situation, the modernizr library will help:</p>
19
<h2>JavaScript Core</h2>
19
<h2>JavaScript Core</h2>
20
<p>But there aren't just polyfills for the DOM. JavaScript itself is also continuously developing, especially in recent years. Many features of modern JavaScript simplify development, so it's hard to work without them. Therefore, almost no project can do without the<a>core-js</a>library. This library covers nearly all the features of modern JavaScript.</p>
20
<p>But there aren't just polyfills for the DOM. JavaScript itself is also continuously developing, especially in recent years. Many features of modern JavaScript simplify development, so it's hard to work without them. Therefore, almost no project can do without the<a>core-js</a>library. This library covers nearly all the features of modern JavaScript.</p>
21
<p>It installs as a project dependency, connected once at the topmost level of the application. So, it does all the work without needing to build the application using<a>webpack</a>:</p>
21
<p>It installs as a project dependency, connected once at the topmost level of the application. So, it does all the work without needing to build the application using<a>webpack</a>:</p>
22
22