Skip to content

Commit

Permalink
do not build the service worker if the file is empty #104
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Oct 15, 2020
1 parent 8fb8103 commit 6795f42
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 74 deletions.
10 changes: 5 additions & 5 deletions css/images.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.image-placeholder-lqip {
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='20');
filter: blur(20px);
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='2');
filter: blur(2px);
}
/*
.image-placeholder-no-js {
Expand All @@ -15,7 +15,7 @@
.image-placeholder-wrapper {
position: relative;
display: inline-block;
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='20');
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='0');
filter: blur(0px);
transition: filter 0.2s ease-out;
}
Expand All @@ -35,8 +35,8 @@
max-height: 100%;
}
.image-placeholder-wrapper :not(.image-placeholder-complete) {
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='20');
filter: blur(20px);
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='2');
filter: blur(2px);
}
.image-placeholder-wrapper .image-placeholder-opacity {
transition: opacity 0.2s ease-out;
Expand Down
92 changes: 46 additions & 46 deletions css/images.less
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.blur-mixin (@value: 20) {
& {
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='20'); // filter: url(#blur-lqip);
filter: blur(~"@{value}px");
}
.blur-mixin (@value: 2) {
& {
-ms-filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='@{value}'); // filter: url(#blur-lqip);
filter: blur(~"@{value}px");
}
}

.image-placeholder-lqip {
.blur-mixin ();
.blur-mixin ();
}

/*
Expand All @@ -16,58 +16,58 @@
visibility: hidden;
}
*/
.image-placeholder-loaded {

transform: translateX(100%);
.image-placeholder-loaded {
transform: translateX(100%);
}

.image-placeholder-wrapper {
position: relative;
display: inline-block;
position: relative;
display: inline-block;

>img {
position: static;
}
> img {
position: static;
}

>.image-placeholder-svg {
position: absolute;
display: block;
left: 0;
top: 0;
width: 100%;
height: 100%;
> .image-placeholder-svg {
position: absolute;
display: block;
left: 0;
top: 0;
width: 100%;
height: 100%;

svg {
max-width: 100%;
max-height: 100%;
}
svg {
max-width: 100%;
max-height: 100%;
}
}

.blur-mixin (0);
transition: filter 0.2s ease-out;
.blur-mixin (0);
transition: filter 0.2s ease-out;

:not(.image-placeholder-complete) {
.blur-mixin ();
:not(.image-placeholder-complete) {
.blur-mixin ();

.image-placeholder-opacity {
// opacity: 0;
}
.image-placeholder-opacity {
// opacity: 0;
}
}

.image-placeholder-opacity {
transition: opacity 0.2s ease-out; // background: #fff;
display: block;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
.image-placeholder-opacity {
transition: opacity 0.2s ease-out; // background: #fff;
display: block;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;

.image-placeholder-element {
display: block;
width: 100%;
height: 100%;
background: 0 0 / cover no-repeat;
}
.image-placeholder-element {
display: block;
width: 100%;
height: 100%;
background: 0 0 / cover no-repeat;
}
}
}
}
5 changes: 0 additions & 5 deletions gzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -1213,11 +1213,6 @@ protected function updateServiceWorker($options)
$preloaded_urls[] = $manifest['start_url'];
}

if (!empty($start_url)) {

$preloaded_urls[] = $start_url;
}

$preloaded_urls = array_values(array_unique($preloaded_urls));

$import_scripts = '';
Expand Down
27 changes: 24 additions & 3 deletions helpers/CSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ public function processHTML($html, array $options = [])
$cssRenderer = new Renderer($css_options);
$headStyle = new Stylesheet();

$fetchFonts = function ($node) use($options, $headStyle) {

if ((string) $node['name'] == 'font-face') {

/**
* @var Element\AtRule $node
*/
$node->addDeclaration('font-display', $options['fontdisplay']);

$query = $node->query('./[@name=src]');

if ($query) {

// copy only the src property of the font-face => the font will not block page loading
// @font-face {
// src: url(...);
// }
$headStyle->append(end($query)->copy()->getRoot());
}
}
};
$parseUrls = function ($html) use($path) {

return preg_replace_callback('~url\(([^)]+)\)~', function ($matches) use($path) {
Expand Down Expand Up @@ -234,7 +255,7 @@ public function processHTML($html, array $options = [])
$cssParser->append($attr['href']);
}

file_put_contents($file, $parseUrls($cssRenderer->render($this->parseBackgroundImages($cssParser->parse()))));
file_put_contents($file, $parseUrls($cssRenderer->render($this->parseBackgroundImages($cssParser->parse()->traverse($fetchFonts, 'enter')))));
}

$links[$position]['links'] = [
Expand Down Expand Up @@ -266,7 +287,7 @@ public function processHTML($html, array $options = [])
if (!is_file($file)) {

$cssParser->load($attr['href']);
file_put_contents($file, $parseUrls($cssRenderer->render($this->parseBackgroundImages($cssParser->parse(), $options))));
file_put_contents($file, $parseUrls($cssRenderer->render($this->parseBackgroundImages($cssParser->parse()->traverse($fetchFonts, 'enter'), $options))));
}
}

Expand Down Expand Up @@ -366,7 +387,7 @@ public function processHTML($html, array $options = [])
if ($parseWebFonts) {

// all fonts with an src attribute
$query[] = '@font-face/src/..';
// $query[] = '@font-face/src/..';
}

if ($parseCritical && !empty($options['criticalcss'])) {
Expand Down
2 changes: 1 addition & 1 deletion worker/dist/browser.administrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// @ts-check

// build 77ad4d7 2020-10-14 21:54:44-04:00
// build 8fb8103 2020-10-14 23:07:21-04:00

if ("serviceWorker" in navigator) {
navigator.serviceWorker.
Expand Down
2 changes: 1 addition & 1 deletion worker/dist/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// @ts-check

// build 77ad4d7 2020-10-14 21:54:44-04:00
// build 8fb8103 2020-10-14 23:07:21-04:00

if ("serviceWorker" in navigator) {
navigator.serviceWorker.
Expand Down
1 change: 1 addition & 0 deletions worker/dist/browser.sync.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion worker/dist/browser.uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
// @ts-check

// build 77ad4d7 2020-10-14 21:54:44-04:00
// build 8fb8103 2020-10-14 23:07:21-04:00

if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
navigator.serviceWorker.getRegistration().then(function (registration) {
Expand Down
13 changes: 7 additions & 6 deletions worker/dist/serviceworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,14 +881,14 @@
* service worker build id
*/
buildid: {
value: "77ad4d7",
value: "8fb8103",
enumerable: true
},
/**
* service worker buid date
*/
builddate: {
value: "2020-10-14 21:54:44-04:00",
value: "2020-10-14 23:07:21-04:00",
enumerable: true
},
/**
Expand Down Expand Up @@ -1657,12 +1657,13 @@
*/

self.addEventListener("fetch", (event) => {
event.respondWith((async function () {

if (!event.url || (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin')) {
if (!event.url || (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin')) {

return fetch(event.request);
}
return;
}

event.respondWith((async function () {

let response;

Expand Down
2 changes: 1 addition & 1 deletion worker/dist/serviceworker.min.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions worker/src/service/sw.service.fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import {
*/

self.addEventListener("fetch", (event) => {
event.respondWith((async function () {

if (!event.url || (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin')) {
if (!event.url || (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin')) {

return fetch(event.request);
}
return;
}

event.respondWith((async function () {

let response;

Expand Down
2 changes: 1 addition & 1 deletion worker_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c22fadaa841cf95cf62c214f8edb67521ea00d0e
d0754001c212d11077e8882cf7bf662d25057caa

0 comments on commit 6795f42

Please sign in to comment.