Skip to content

Commit

Permalink
Fixed whitespace between tags
Browse files Browse the repository at this point in the history
  • Loading branch information
shinsenter committed Apr 17, 2019
1 parent 7c295e6 commit 504312a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
25 changes: 13 additions & 12 deletions README.md
Expand Up @@ -94,24 +94,25 @@ require_once __DIR__ . '/vendor/shinsenter/defer.php/defer.php';
$defer = new \shinsenter\Defer();

// Library injection
$defer->append_defer_js = false;
$defer->default_defer_time = 10;
$defer->append_defer_js = false;
$defer->default_defer_time = 10;

// Page optimizations
$defer->enable_preloading = true;
$defer->enable_dns_prefetch = true;
$defer->fix_render_blocking = true;
$defer->minify_output_html = true;
$defer->enable_preloading = true;
$defer->enable_dns_prefetch = true;
$defer->fix_render_blocking = true;
$defer->minify_output_html = true;

// Tag optimizations
$defer->enable_defer_css = true;
$defer->enable_defer_scripts = true;
$defer->enable_defer_images = true;
$defer->enable_defer_iframes = true;
$defer->enable_defer_background = true;
$defer->enable_defer_css = true;
$defer->enable_defer_scripts = true;
$defer->enable_defer_images = true;
$defer->enable_defer_iframes = true;
$defer->enable_defer_background = true;
$defer->enable_defer_fallback = true;

// Web-font optimizations
$defer->defer_web_fonts = true;
$defer->defer_web_fonts = true;

// Image and iframe placeholders
$defer->empty_gif = '';
Expand Down
55 changes: 28 additions & 27 deletions src/DeferInterface.php
Expand Up @@ -77,6 +77,7 @@ abstract class DeferInterface

// Content tags
const AUDIO_TAG = 'audio';
const BR_TAG = 'br';
const BODY_TAG = 'body';
const EMBED_TAG = 'embed';
const FRAME_TAG = 'frame';
Expand Down Expand Up @@ -113,33 +114,33 @@ abstract class DeferInterface
const PRELOAD_WORKER = 'worker';

// Tag attributes
const ATTR_ALT = 'alt';
const ATTR_AS = 'as';
const ATTR_ASYNC = 'async';
const ATTR_CHARSET = 'charset';
const ATTR_CLASS = 'class';
const ATTR_CONTENT = 'content';
const ATTR_CROSSORIGIN = 'crossorigin';
const ATTR_DATA_IGNORE = 'data-ignore';
const ATTR_DATA_SRC = 'data-src';
const ATTR_DATA_SRCSET = 'data-srcset';
const ATTR_DATA_STYLE = 'data-style';
const ATTR_DEFER = 'defer';
const ATTR_HEIGHT = 'height';
const ATTR_HREF = 'href';
const ATTR_LANGUAGE = 'language';
const ATTR_ID = 'id';
const ATTR_MEDIA = 'media';
const ATTR_NAME = 'name';
const ATTR_ONLOAD = 'onload';
const ATTR_REL = 'rel';
const ATTR_SRC = 'src';
const ATTR_SRCSET = 'srcset';
const ATTR_SIZES = 'sizes';
const ATTR_STYLE = 'style';
const ATTR_TITLE = 'title';
const ATTR_TYPE = 'type';
const ATTR_WIDTH = 'width';
const ATTR_ALT = 'alt';
const ATTR_AS = 'as';
const ATTR_ASYNC = 'async';
const ATTR_CHARSET = 'charset';
const ATTR_CLASS = 'class';
const ATTR_CONTENT = 'content';
const ATTR_CROSSORIGIN = 'crossorigin';
const ATTR_DATA_IGNORE = 'data-ignore';
const ATTR_DATA_SRC = 'data-src';
const ATTR_DATA_SRCSET = 'data-srcset';
const ATTR_DATA_STYLE = 'data-style';
const ATTR_DEFER = 'defer';
const ATTR_HEIGHT = 'height';
const ATTR_HREF = 'href';
const ATTR_LANGUAGE = 'language';
const ATTR_ID = 'id';
const ATTR_MEDIA = 'media';
const ATTR_NAME = 'name';
const ATTR_ONLOAD = 'onload';
const ATTR_REL = 'rel';
const ATTR_SRC = 'src';
const ATTR_SRCSET = 'srcset';
const ATTR_SIZES = 'sizes';
const ATTR_STYLE = 'style';
const ATTR_TITLE = 'title';
const ATTR_TYPE = 'type';
const ATTR_WIDTH = 'width';

const UNIFY_OTHER_LAZY_SRC = [
'data-src',
Expand Down
6 changes: 4 additions & 2 deletions src/DeferOptimizer.php
Expand Up @@ -411,9 +411,11 @@ protected function minifyOutputHTML()
$trimmed = ' ';
}
} else {
if ($node->previousSibling) {
if ($node->previousSibling && $node->previousSibling->nodeName !== static::BR_TAG) {
$trimmed = ' ' . $trimmed;
} elseif ($node->nextSibling) {
}

if ($node->nextSibling && $node->nextSibling->nodeName !== static::BR_TAG) {
$trimmed = $trimmed . ' ';
}
}
Expand Down

0 comments on commit 504312a

Please sign in to comment.