Expand my Community achievements bar.

Help shape the future of AI assistance by participating in this quick card sorting activity. Your input will help create a more effective system that better serves your needs and those of your colleagues.
SOLVED

Future of the Document.Write issue

Avatar

Level 1

We would like to know what Adobe is doing to address the document.write issue that google is warning us about?

Our development team pointed out some concerns that we have in the following excerpt:

document.write is being used to inject scripts into the page. This is bad practice, and Google Chrome warns us about it for a couple of reasons.

  1. It's bad for performance because it blocks render of items that follow it in the page. Tangentially related to this ticket (but specifically important for performance) is the fact that so many scripts are loaded this way. Could these be consolidated as well as minified+gzipped?
  2. Since it's bad for performance, Chrome has decided to only wait so long on such resources to load before giving up on them and excluding them from the page. In other words a network hiccup or a slow connection can cause those scripts to be aborted and never loaded. I would think this could result in data loss for Analytics.
1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Eric. There are a few variations of warnings that Chrome might show regarding the use of document.write. The only one you should ever see due to Launch is one that says:

[Violation] Avoid using document.write().


The one exception to this is when you have "custom code" that uses document.write in which case the warning you see may be due to the custom code itself.

The "avoid using document.write" warning is shown whenever you use document.write for anything and have verbose mode enabled within the console. In our case, we use document.write to execute the "custom code" action on rules that are using page top or page bottom events. It's important to note that we don't load external scripts using document.write, so there is no blocking of the browser's parser which is typically the performance concern.

If you are concerned about the warning, we recommend you do not use the custom code action on rules that are using the page top or page bottom event. Rules using any of the other events shouldn't trigger the warning about document.write.

If you're seeing other warnings from Chrome regarding the use of document.write besides the one mentioned above, please let us know. Providing a URL where we can see the behavior would be helpful. The warning that we're more concerned about says "A parser-blocking, cross-origin script, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity." This warning we specifically wish to avoid and was one of the goals when building Launch.

View solution in original post

2 Replies

Avatar

Employee

There have been many internal conversations on this topic.  At this moment, I'd suggest you take a look at the correct answer from one of our developers on this thread: Re: Load Order for Rules :: DTM vs. Launch​.

That response provides a whole bunch of info on how we use document.write() in DTM and how we use it in Launch. In Launch it only gets used for Page Top and Page Bottom rules, so if you can avoid those I think you'll never see it.  That should be simpler once we get an MCID ready event to trigger rules.

There's also some info in that response on about how multiple scripts will be loaded.  With our next release, those scripts will be minified (not sure about GZipped), but no current plans to consolidate them.

I'll ask the dev team to take a look at this and provide any additional info.

Avatar

Correct answer by
Employee

Hi Eric. There are a few variations of warnings that Chrome might show regarding the use of document.write. The only one you should ever see due to Launch is one that says:

[Violation] Avoid using document.write().


The one exception to this is when you have "custom code" that uses document.write in which case the warning you see may be due to the custom code itself.

The "avoid using document.write" warning is shown whenever you use document.write for anything and have verbose mode enabled within the console. In our case, we use document.write to execute the "custom code" action on rules that are using page top or page bottom events. It's important to note that we don't load external scripts using document.write, so there is no blocking of the browser's parser which is typically the performance concern.

If you are concerned about the warning, we recommend you do not use the custom code action on rules that are using the page top or page bottom event. Rules using any of the other events shouldn't trigger the warning about document.write.

If you're seeing other warnings from Chrome regarding the use of document.write besides the one mentioned above, please let us know. Providing a URL where we can see the behavior would be helpful. The warning that we're more concerned about says "A parser-blocking, cross-origin script, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity." This warning we specifically wish to avoid and was one of the goals when building Launch.