How to Minify Google AdSense JS?

ⅰ亾dé卋堺 提交于 2019-12-08 07:26:42

问题


Whenever I minify the AdSense script I got from Google, it stops working. Any ideas why?

Original Code:

<script type="text/javascript"><!--
google_ad_client = "xxx";
/* Ad 1 */
google_ad_slot = "2668798369";
google_ad_width = 160;
google_ad_height = 600;
//-->

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

Minified Code:

<script type="text/javascript"><!--google_ad_client = "xxx";/* Ad 1 */google_ad_slot = "2338787596";google_ad_width = 200;google_ad_height = 200;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

The minification is being done by Smarty's {strip} tags.


回答1:


The problem is the HTML comment tags at the start and end of the first script tag. You don't need them, they're just there to work around Netscape 1.0

Try replacing your minified script with this

<script type="text/javascript">google_ad_client="xxx";google_ad_slot="2668798369";google_ad_width=160;google_ad_height=600;</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js">



回答2:


i think you left out this part:

//-->



回答3:


Try to remove the <!--

Hope it helps




回答4:


It'll be the <!-- - this can mean 'treat this line as a comment'. It's an old compatibility hack for browers that didn't support JavaScript.

Either remove it or add a linebreak afterwards, i.e.

<script type="text/javascript"><!--
google_ad_client="xxx"; ...

though I can't see what minifying here is gaining you - there's nothing that can be renamed or compressed.




回答5:


Look out for this:

<!-- and -->



来源:https://stackoverflow.com/questions/4878724/how-to-minify-google-adsense-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!