title: What is the risk of global polyfills in an external script breaking the functionality of a website?
body: <p>The documentation for <a href="https://babeljs.io/docs/en/babel-polyfill" rel="nofollow noreferrer">@babel/polyfill</a> has the following note:</p>
  <blockquote>
  <p>If you are looking for something that won't modify globals to be used in a tool/library, checkout the <a href="https://babeljs.io/docs/en/babel-plugin-transform-runtime" rel="nofollow noreferrer">transform-runtime</a> plugin.</p>
  </blockquote>
  <p>On the <a href="https://babeljs.io/docs/en/babel-plugin-transform-runtime" rel="nofollow noreferrer">transform-runtime</a> documentation, it says the following:</p>
  <blockquote>
  <p>While this [@babel/polyfill usage] might be ok for an app or a command line tool, it becomes a problem if your code is a library which you intend to publish for others to use or if you can't exactly control the environment in which your code will run.</p>
  </blockquote>
  <p>More generally speaking, a lot of articles explaining the use of polyfills say that you <strong>may</strong> want to use a different solution <strong>if you care about polluting the global namespace</strong>.</p>
  <p>In my understanding, most polyfills are loaded conditionally. If an implementation already exists, the polyfill will not overwrite it. My question is: under what kind of circumstances can polyfills in an external script cause an existing website to break? The only reason that I have been able to find so far is that the external script might load a polyfill earlier than the code in the website itself. This <em>may</em> lead to problems, but when these polyfills are based on web standards, their behavior <em>should</em> be the same. What is the likelihood of there still being serious conflicts?</p>
  <p>I found an interesting discussion about this on a <a href="https://github.com/w3ctag/polyfills/issues/6" rel="nofollow noreferrer">github issue</a>. This talks mostly about modules in the NPM ecosystem though, whereas I'm mostly interested in external scripts that facilitate things like widgets or embeds.</p>
  <p>Any personal experience or links to discussions and articles on the subject is appreciated!</p>
  <p>UPDATE: One of the main reasons for this question is that there were some issues with transform-runtime. With the new release of core-js and babel these issues seem to have been addressed. Regardless I am still interested in answers to the original question above.</p>