I don't think whitespace removal would get you punished, but if the client code *has* to be preserved, here are two functions to add to the WPSCMin class in WPSCMin.php (jsmin + a replacement for minify):
public static function jsmin($js) { // if has google client code, don't minify return (false !== strpos($js, 'google_ad_client')) ? trim($js) : JSMin::minify($js); }
// Minifies string referenced by $html, if $this->enabled is TRUE public function minify(& $html) { if (!$this->enabled) return;
// Include Minify components unless they have already been required if (!class_exists('Minify_HTML')) { require('min/lib/Minify/HTML.php'); ini_set('include_path', ini_get('include_path').':'.dirname(__FILE__).'/min/lib'); require('min/lib/Minify/CSS.php'); require('min/lib/JSMin.php'); }
> > I don't think whitespace removal would get you punished, but if the
> > client code *has* to be preserved, here are two functions to add to the
> > WPSCMin class in WPSCMin.php (jsmin + a replacement for minify):
> > public static function jsmin($js) {
> > // if has google client code, don't minify
> > return (false !== strpos($js, 'google_ad_client'))
> > ? trim($js)
> > : JSMin::minify($js);
> > }
> > // Minifies string referenced by $html, if $this->enabled is TRUE
> > public function minify(& $html) {
> > if (!$this->enabled)
> > return;
> > // Include Minify components unless they have already been required
> > if (!class_exists('Minify_HTML')) {
> > require('min/lib/Minify/HTML.php');
> > ini_set('include_path',
> > ini_get('include_path').':'.dirname(__FILE__).'/min/lib');
> > require('min/lib/Minify/CSS.php');
> > require('min/lib/JSMin.php');
> > }
kia wrote: > its about the missing html comments <!-- and --> in google ads (not > comments generally). its possible to skip them/dont minify them?
(Sigh) due to an annoying PHP5 feature preventing subclassing Minify_HTML (static methods always bind "self" to the defining class), you'll actually have to edit Minify/HTML.php directly to do what you want:
1. Find the method _removeScriptCB (line 184)
2. Insert the following at the very beginning of the code (line 186):
if (false !== strpos($m[3], 'google_ad_client')) { // only trim whitespace outside the script tags return self::_reservePlace(trim($m[0])); }
Since this bypasses JSMin, you can remove the hacking we did to WPSCMin.php
I'm the author of the WPSCMin mod ... just wanted to let you know I'm
going to put out a new version with the older callback syntax in it,
as Steve suggests. Also, I'll test against the 0.9.1 WP Super Cache
that came out a week or two ago and make sure everything still works.
And since Steve was so helpful to find this bug, I'll chime in on the
Adsense question since I've done a lot of work on this and know some
people at Google (I'm north of SF). Google absolutely does not care if
you remove the HTML or JS comments from their code block (I think the
Q&A linked https://www.google.com/adsense/support/bin/answer.py?hl=en&answer=66096 pretty much says that). They mostly care about things that actually
change the content/functionality of the ads, people clicking their own
ads, clickfarms etc. They also don't want to have to provide HTML help
to millions of people, so they just say "don't change the code" a lot.
But you can add/edit/delete comments and whitespace all you want, just
understand you're the one responsible if you break something.
joel.ha...@gmail.com wrote: > I'm the author of the WPSCMin mod ... just wanted to let you know I'm > going to put out a new version with the older callback syntax in it,
Thanks, Joel. Feel free to refer markup output bugs to this list. In the meantime I'm going to make the Minify_HTML class easier to extend so users can change its behavior. In that light having a way to change the HTML minifier without modifying WPSCMin.php might be nice eventually.
> people at Google (I'm north of SF). Google absolutely does not care if > you remove the HTML or JS comments from their code block (I think the
I figured as much, but I also suspect there may be orgs that *do* rely on specific HTML/JS comments and Minify_HTML should be flexible enough to allow that.
> joel.ha...@gmail.com wrote:
> > I'm the author of the WPSCMin mod ... just wanted to let you know I'm
> > going to put out a new version with the older callback syntax in it,
> Thanks, Joel. Feel free to refer markup output bugs to this list. In the
> meantime I'm going to make the Minify_HTML class easier to extend so
> users can change its behavior. In that light having a way to change the
> HTML minifier without modifying WPSCMin.php might be nice eventually.
> > people at Google (I'm north of SF). Google absolutely does not care if
> > you remove the HTML or JS comments from their code block (I think the
> I figured as much, but I also suspect there may be orgs that *do* rely
> on specific HTML/JS comments and Minify_HTML should be flexible enough
> to allow that.