CDATA being removed by rewrite_javascript filter

18 views
Skip to first unread message

u...@zoey.com

unread,
Feb 16, 2018, 11:47:35 AM2/16/18
to ngx-pagespeed-discuss
Hello,

I have been searching around the forums but am unable to find a solution. If we have the "rewrite_javascript" filter enabled all CDATA is removed in the source. This is causing other Google services to break such as Adwords or third parties. The CDATA comments must be printed out. How can we force Pagespeed to not touch this information? We are not able to serve the pages as XHTML - or at least we've tried and it's made no difference.

For example:

<script type="text/javascript">
//<![CDATA[
var placeholder = document.getElementById('zoey_search_mini_form_mobile').querySelector('input').getAttribute('placeholder');
var searchForm = new Varien.searchForm('zoey_search_mini_form_mobile', 'search_mobile', 'Search...');
//]]>
</script>

gets rewritten into

<script type="text/javascript">var placeholder=document.getElementById('zoey_search_mini_form_mobile').querySelector('input').getAttribute('placeholder');var searchForm=new Varien.searchForm('zoey_search_mini_form_mobile','search_mobile','Search...');</script>

While not a big deal for this example, for Google Adwords things break because Google cannot find the CDATA.

Is there a way to just have a pagespeed modification to not strip out comments in Javascript?

Otto van der Schaaf

unread,
Feb 16, 2018, 5:24:07 PM2/16/18
to ngx-pagesp...@googlegroups.com
You could try disabling rewrite_javascript, or use url control [1] to disallow scripts that shoud be left alone.

With regard to changing the content-type to xhtml,
Did you see https://groups.google.com/forum/#!topic/mod-pagespeed-discuss/DY-PKRbRZwg ?


Otto

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.
Visit this group at https://groups.google.com/group/ngx-pagespeed-discuss.
For more options, visit https://groups.google.com/d/optout.

u...@zoey.com

unread,
Feb 16, 2018, 5:30:14 PM2/16/18
to ngx-pagespeed-discuss
Hi Otto,

Nice to hear from you again :)

I would prefer to not have a nuclear approach to a localized problem. Completely disabling rewrite_javascript negates using PageSpeed way too much.

Blocking URLs is not feasible. These CDATA blocks are also inline <script> tags and not JS files that we could filter out.

I did see that post, we use NginX, and I was unable to get the Content-Type to change without breaking the site completely. We also have various proxies in front of the final NginX server so where would we set the Content-Type header? On the pagespeed server or somewhere upstream?

I tried to poke around the source to see if there was a way to not remove comments from Javascript but I couldn't find it. Is it possible to modify our local build to do this?

Uri
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

Otto van der Schaaf

unread,
Feb 16, 2018, 5:43:48 PM2/16/18
to ngx-pagesp...@googlegroups.com
It probably is possible to create a patch for local use to get the module to behave like you need.

To start out, I would hook up a breakpoint in gdb in this JavascriptFilterTest/XHtmlInlineJavascript:

Hopefully stepping through the code from there will get you to the right knobs to tweak.

Otto

To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.

Uri Foox

unread,
Feb 16, 2018, 5:47:12 PM2/16/18
to ngx-pagesp...@googlegroups.com
Thanks but creating the patch myself is outside of what I can do. I can certainly implement it and test it but I couldn't code it. 

If you have any other recommendations let me know.

To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ngx-pagespeed-discuss/wxTovXubqnI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.



--
Uri Foox | Zoey
http://www.zoey.com
Reply all
Reply to author
Forward
0 new messages