Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Bug fix #38

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ $defer->empty_src = '';
$defer->use_color_placeholder = true;
$defer->use_css_fadein_effects = true;

// Manually add deferjs library script tag
// $defer->manually_add_deferjs = true;

// Blacklist
$defer->do_not_optimize = [
'document\.write\s*\(',
Expand Down
3 changes: 2 additions & 1 deletion src/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public function toHtml()
$output = $this->dom->saveHtml();
}

$output = $this->script_decode($this->entity2charset($output, $this->charset));
$output = $this->script_decode($output);
$output = $this->entity2charset($output, $this->charset);

if (!empty($this->bug72288_body)) {
$output = preg_replace('/(<body[^>]*>)/mi', $this->bug72288_body, $output, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/DeferOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ protected function addDeferJs()
return;
}

$extra_scripts = [];
$the_anchor = $this->head->childNodes->item(0);
$extra_scripts = [];
$the_anchor = $this->head->childNodes->item(0);

// Append the defer.js library and polyfill
if (!$this->manually_add_deferjs) {
Expand Down Expand Up @@ -434,7 +434,7 @@ protected function minifyOutputHTML()
}

if ($trimmed != $node->nodeValue) {
$node->nodeValue = htmlspecialchars($trimmed);
$node->nodeValue = $trimmed;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/DeferParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ protected function script_encode($html)
}

$next = '@@@SCRIPT@@@' . count($this->bug_script_templates) . '@@@SCRIPT@@@';

$this->bug_script_templates[$next] = trim($matches[2]);

return "{$matches[1]}{$next}{$matches[3]}";
Expand Down
5 changes: 3 additions & 2 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
$defer->use_css_fadein_effects = true;
$defer->use_color_placeholder = false;

$defer->manually_add_deferjs = true;
// Manually add deferjs library script tag
// $defer->manually_add_deferjs = true;

// $defer->clearCache();
$defer->clearCache();

// Scan test files
$list = glob(INPUT . '*.html');
Expand Down