Android (5.0.1) Chrome removes javascript spaces and comments, is there any way to stop this?

In addition to being debugging almost impossible, this new behavior breaks my site where I use the javascript heredoc technique, ( Javascript heredoc ), which depends on the use of comments.

I'm not sure that I involuntarily turned it on, and this is a rare occurrence, or if it is a new Android feature. My concern is that I use the javascript heredoc technique on several different sites, and this behavior will break those sites.

Has anyone else experienced this?

Is there a way the server can stop this?

Is there an alternative to the heredoc javascript method?

0
javascript android comments heredoc whitespace
Dec 31 '15 at 14:38
source share
2 answers

This problem was caused by chrome data compression ( https://developer.chrome.com/multidevice/data-compression .) Thanks Slaks for heads-up, or I would have skipped it.

As soon as I turned it off - this is in the Chrome settings - reduce the data usage (after the content settings and before Chrome) my site started working again.

To fix this for other users who, like me, do not even know that they are using this, I added the following code, which I found in the following two links:

<FilesMatch "\.(css|js)$"> <IfModule mod_headers.c> Header set Pragma "public" Header set Cache-Control "no-transform,public, must-revalidate, proxy-revalidate" </IfModule> FileETag MTime Size </FilesMatch> 

The important part tells Google "no-transform" in javascript through the Cache-Control directive. I did this for .js and .css files, although in the future I might add additional types.

And I added headers.load to the mods available so that it has mod_headers.

http://mobiforge.com/design-development/setting-http-headers-advise-transcoding-proxies

Apache -Caching: setting response headers in Apache 2+.

After restarting Apache, everything is working fine.

In terms of the 3rd question, is there a workaround for the heredoc javascript method, I have no answer, but perhaps this scenario indicates that this method is not without problems.

+1
Dec 31 '15 at 17:09
source share

I am the technical leader for the Google proxy. Our proxy does remove comments from JS files, which should be safe - although there are some tools that (in my opinion :-) rely on JS comments to work. In general, there is no good way to detect this, so we rely on the Cache-Control: no-transform header. If you have suggestions on the best ways to avoid this, I would appreciate it.

0
Feb 05 '15 at 23:22
source share



All Articles