Skip to content

Commit

Permalink
ignored javascript are removed from the page #96
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed May 10, 2020
1 parent c9d34fd commit ac8b1d5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 52 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@

- remove duplicated path the file name #88
- preserve IE conditional comments #88
- \[bug\] the minification produced invalid HTML when the HTML provided had missing space between attributes #88
- remove the length restriction of the manifest short_name #78
- compress cache files. If the client advertises compression support, then send the compressed file. Brotli support requires the brotli extension #89
- fix security and performance issues induced by links with _target=\_blank_ attribute #91
- change default pwa display to _standalone_ #78
- \[bug\] fix invalid configuration path #94
- \[performance\] compress cached files using brotli or gzip
- Add \.ico as a supported PWA icon format #78
- Add purpose property to the PWA manifest options #78
- Add screenshots property to the PWA manifest options #78
- asynchronously initialize the service worker using \<script defer\> #78
- \[bug\] fix invalid configuration path #94
- \[bug\] the minification produced invalid HTML when the HTML provided had missing space between attributes #88
- \[bug\] the protocol is removed in the HTML content instead of href|src attributes only
- \[bug\] fix an uncaught javascript error in the service worker js #78
- \[bug\] fix 404 error when Hotlink protection is ON and cache files is OFF #78
- remove the length restriction of the manifest short_name #78
- \[bug\] fix 404 error when Hotlink protection is ON and cache files is OFF #78i
- \[bug\] fix ignored javascript are removed from the page #96
## 2.7.3

- change Upgrade-Insecure-Requests to be used as a CSP setting instead of an HTTP header
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Here are some features provided by this plugin

- HTML minification
- preserve IE conditional comments
- precompress assets using brotli or gzip

## Javascript

Expand Down
8 changes: 6 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Here are some features provided by this plugin
## HTML

- HTML minification
- preserve IE conditional comments
- precompress assets using brotli or gzip

## Javascript

Expand Down Expand Up @@ -42,9 +44,11 @@ Here are some features provided by this plugin

## Performance

- configurable HTTP caching headers
- optimizations are enforced when the client sends [Save-Data HTTP header](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/save-data/)
- dns prefetch
- profile plugin performance using HTTP server timing headers
- precompressed cached files using brotli or gzip.

## Service Worker

Expand All @@ -53,6 +57,7 @@ Here are some features provided by this plugin
- background sync
- web share target level 2
- web push notifications using One Signal
- immediately update the service worker when the manifest settings change

## Content Security Policy (CSP)

Expand All @@ -66,7 +71,6 @@ Configure almost every csp level 3 settings to your liking:
## Security

- Sub Resource Integrity
- Content Security Policy Level 3: control execution of scripts, css, frames, workers in every web page
- HSTS header configuration
- XSS-PROTECTION header configuration
- X-Frames-Options configuration
Expand All @@ -77,4 +81,4 @@ Configure almost every csp level 3 settings to your liking:
- configure link lifetime

The complete list of features is available in the [online documentation](https://tbela99.github.io/gzip/)
and the [change log](https://github.com/tbela99/gzip/blob/master/CHANGELOG.md)
and the [change log](./CHANGELOG.md)
69 changes: 23 additions & 46 deletions helpers/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ public function processHTML ($html, array $options = []) {
return $matches[0];
}

// ignore custom type
if (isset($attributes['src'])) {

$name = GZipHelper::getName($attributes['src']);

foreach ($remove as $r) {

if (strpos($name, $r) !== false) {

return '';
}
}

foreach ($ignore as $i) {

if (strpos($name, $i) !== false) {

$attributes['data-ignore'] = 'true';
break;
}
}
}

if (isset($attributes['data-ignore'])) {

unset($attributes['data-ignore']);
Expand All @@ -92,25 +115,6 @@ public function processHTML ($html, array $options = []) {
// ignore custom type
if (isset($attributes['src'])) {

$name = GZipHelper::getName($attributes['src']);

foreach ($remove as $r) {

if (strpos($name, $r) !== false) {

return '';
}
}

foreach ($ignore as $i) {

if (strpos($name, $i) !== false) {

$sources['ignored'][$position][$name] = $attributes['src'];
return '';
}
}

if ($fetch_remote && preg_match('#^(https?:)?//#', $name)) {

$remote = $name;
Expand Down Expand Up @@ -147,8 +151,6 @@ public function processHTML ($html, array $options = []) {

}, $html);

// $profiler->mark('done parse <script>');

$hashFile = GZipHelper::getHashMethod($options);

if (!empty($options['minifyjs'])) {
Expand Down Expand Up @@ -251,14 +253,11 @@ public function processHTML ($html, array $options = []) {

$data = implode(';', $js);

// foreach($js as $key => $data) {

if (!empty($data)) {

$jSqueeze = new JSqueeze();
$sources['inline'][$position] = [trim($jSqueeze->squeeze($data), ';')];
}
// }
}
}
}
Expand All @@ -271,28 +270,6 @@ public function processHTML ($html, array $options = []) {

$async = false;

if (!empty($sources['ignored'])) {

foreach ($sources['ignored'] as $position => $fileList) {

$attr = '';
$hasScript = !empty($sources['inline'][$position]) && empty($files[$position]);

if ($hasScript) {

$async = true;
}

$script[$position] .= "\n".'<script async defer src="' . array_shift($fileList) . '"'.$attr.'></script>';

if ($hasScript) {

$script[$position] .= "\n".'<script type="text/foo">' . trim(implode(';', $sources['inline'][$position]), ';') . '</script>';
unset($sources['inline'][$position]);
}
}
}

if (!empty($sources['files'])) {

foreach($sources['files'] as $position => $fileList) {
Expand Down

0 comments on commit ac8b1d5

Please sign in to comment.