document.write
The JavaScript function document.write
will alter the markup document while it is being parsed by the browser. Scripts that add resources to the head
, like many 3rd party scripts do, will block the load
event as they add loading tasks. These loading tasks mostly target resources that are not under your control. If those resources have bad response times, in worst case the browser could run into a timeout, this will severely delay loading your content.
With the document-write-deferring
directive enabled the document.write
calls will be covered and only executed after the document has been loaded.
Enable in conf/config.xml
:
<config>
<acceleration>
<document-write-deferring/>
</acceleration>
</config>
ai-document-write-defer
attributeWhen document-write-deferring
is enabled, certain script
elements can be excluded from the deferring process by marking them with ai-document-write-defer="false"
.
<script>
/* this document.write will be deferred: */
document.write('<p>deferring<\/p>');
</script>
<script ai-document-write-defer="false">
/* this document.write will _not_ be deferred: */
document.write('<p>NO DEFERRING!<\/p>');
</script>
If your scripts truly rely on altering the document while it is being parsed, you should not enable this directive. Also this process can not cover any document.write
s that are in external scripts that are not written into the document by document.write
.