Enabling HTML optimization strips <!CDATA comments from inline JavaScript #69

Pumppa opened this Issue Oct 24, 2016 · 1 comment


None yet

2 participants

Pumppa commented Oct 24, 2016

Greetings, reporting from WP 4.6.1 & autoptimize 2.1.0 operating in tandem with WP super cache.

In short: CDATA is removed from the inline javascript fields upon html optimization being turned on. This removal happens. Even if every other optimization (JS & CSS) is disabled completely. This removal is not effected by: "Keep html comments", Exclude scripts from Autoptimize, or Exclude CSS options. The only way to prevent CDATA from being removed is by adding tag to the code.

This removal effects things like Google Conversion tracking javascript. Which functions in following format. It is also noteworthy that despite adding the google_conversion_id to exclusion list, the cdata comments will still disappear.

/* <![CDATA[ */
var google_conversion_id = 000000000;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "AVCDEFGHIJ25LMN";
var google_remarketing_only = false;
/* ]]> */

The issue effects Autoptimize's own variable autoptimize_ajax_object (Warning about cache might not have been purged successfully inserted into html source)

As well as effecting Disqus comment system variable countVars which contains disqusShortname

While most browsers manage work without the CDATA information Google has stated the following: "While most browsers can properly render the AdWords Remarketing snippet in the absence of CDATA comments, other browsers will fail to properly execute the script. This will result in conversions under-reporting."

Cheers and have a nice day.

futtta commented Oct 24, 2016

while this is true, I consider this very low priority; I don't know of any browser that needs the CDATA. If you consider this important you'll have to disable HTML optimization (which is not that important anyway).


@futtta futtta added the wontfix label Oct 25, 2016
@futtta futtta closed this Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment