最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Minify Google AdSense JS? - Stack Overflow

programmeradmin2浏览0评论

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=".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=".js"></script>

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

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./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./pagead/show_ads.js"></script>

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

Share Improve this question edited Feb 2, 2011 at 19:15 StackOverflowNewbie asked Feb 2, 2011 at 19:08 StackOverflowNewbieStackOverflowNewbie 40.7k114 gold badges290 silver badges452 bronze badges 1
  • You probably can't do this as google says you can't change the ads code itself. – justyy Commented Aug 21, 2014 at 14:58
Add a ment  | 

5 Answers 5

Reset to default 2

The problem is the HTML ment 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./pagead/show_ads.js">

i think you left out this part:

//-->

Try to remove the <!--

Hope it helps

It'll be the <!-- - this can mean 'treat this line as a ment'. It's an old patibility 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 pressed.

Look out for this:

<!-- and -->

发布评论

评论列表(0)

  1. 暂无评论