Ideas for Arc XP

Fusion Engine document.write injection

We are seeing that under elpais.com and its domain pages a script is being injected with a document.write statement.

Inside our default outputType we are including the <Libs> React Component that introduces the different libraries and code processed by Fusion Engine. Among the code injected, there's this code:

<script type="application/javascript">if((window.Object && window.Object.assign)||!window.Promise||!window.Symbol||!window.fetch){document.write('<script type="application/javascript" src="/pf/dist/engine/polyfill.js?d=XXX" defer=""><\/script>')}</script>

If you go to any page in https://elpais.com and you inspect the code, you will see this code appearing in the <head> of the document.

Performance guidelines recommend avoid document.write statements because they delay the display of page content: https://web.dev/no-document-write/

You could consider modifying this code in Fusion Engine and replace it with another approach like using "createElement" JavaScript functions: https://blog.dareboost.com/en/2016/09/avoid-using-document-write-scripts-injection/

  • Guest
  • Sep 9 2020
  • Future consideration
  • Attach files
  • Sean Shannon commented
    September 15, 2020 19:46

    After examining this issue, we've determined that the document.write injection in this case is more or less necessary to enable loading polyfills for older browsers - there isn't a great solution for loading polyfills dynamically that doesn't use document.write some way or another. That being said, we will continue to evaluate other polyfill solutions that work for both old and new browsers without impacting performance negatively.