Digital marketers often utilize the JavaScript document.write method as a mechanism to avoid a common site performance issue called the ‘web page flicker effect.’ But there is a downside to using the document.write approach. Douglas Crockford, best known for popularizing the JSON format, pointed out on his website some of the challenges because of its dependency on timing. “If document.write is called before the onload event, it appends or inserts text into the page. If it is called after onload, it completely replaces the page, destroying what came before.”

Balancing site performance and business requirements are synonymous with a customer-centric strategy. In 2011 in an effort to improve site reliability, usability and speed, Tealium started offering asynchronous tagging. Those able to utilize the Tealium Asynchronous Library during implementation, realized the most value.

document.write-image-2

However, sometimes business requirements temporarily trump implementation standards. The result? The need to utilize synchronous JavaScript code. Using synchronous code can have a substantially negative impact on a site. This topic has been discussed in a previous post about why tags hurt your site. To alleviate this impact, our customers have the option to run Tealium Synchronous Library in addition to Tealium Asynchronous Library, because synchronous JavaScript code cannot exist in the same file as asynchronous code.

document.write-image-3The Tealium Synchronous Library can alleviate issues with JavaScript timing. The bigger problems arise when this Synchronous Library is used to execute the notorious document.write.

As Crockford states, “document.write encourages bad structure, in which script and markup are intermingled. A cleaner structure has minimal interaction between markup and script.”

If you want to see an example of an alternative asynchronous solution, check out Tealium’s integration with Optimizely.

Web browser engineers have tolerated the use of document.write for many years, however this is coming to an end. Google has even announced Chrome will start blocking document.write for 2G users.

We encourage our clients, vendors and partners to join the effort and remove this code from all implementations. As we attempt to integrate seamlessly with third parties, composability implies a shared responsibility for all. The user experience is shaped at every point of the funnel, and for customer-centric digital marketers, there is no other substitution when it comes to managing and creating great experiences that have the power to shape the perception of a brand.

Post Author

Hilary Noonan
Hilary is Director of Content at Tealium.

Sign Up for Our Blog

By submitting this form, you agree to Tealium's Terms of Use and Privacy Policy.
Back to Blog

Want a CDP that works with your tech stack?

Talk to a CDP expert and see if Tealium is the right fit to help drive ROI for your business.

Get a Demo