From 9c80c86534809b05d9fbbfe12fc30ae32c605b8e Mon Sep 17 00:00:00 2001 From: shinsenter <2082119+shinsenter@users.noreply.github.com> Date: Sat, 17 Apr 2021 10:28:18 +0900 Subject: [PATCH 1/5] Do not apply lazy-load for stylesheets with callbacks --- src/Resolvers/LinkResolver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Resolvers/LinkResolver.php b/src/Resolvers/LinkResolver.php index 7d5da49..aab815f 100644 --- a/src/Resolvers/LinkResolver.php +++ b/src/Resolvers/LinkResolver.php @@ -289,6 +289,7 @@ public function lazyload() // and "onload" attribute is not provided if (!$this->isCss() || $this->node->hasAttribute('onload') || + $this->node->hasAttribute('onerror') || $this->skipLazyloading('href')) { return false; } From 9078095c6dd9fcac72a6383f4427246bd88b6024 Mon Sep 17 00:00:00 2001 From: shinsenter <2082119+shinsenter@users.noreply.github.com> Date: Fri, 14 May 2021 22:26:57 +0900 Subject: [PATCH 2/5] Updated libraries --- .php_cs => .php-cs-fixer.php | 4 +- composer.json | 2 +- composer.lock | 242 +++++++++++++++++++------------ src/Elements/CommonDomTraits.php | 2 +- tests/helpers.php | 2 +- 5 files changed, 153 insertions(+), 99 deletions(-) rename .php_cs => .php-cs-fixer.php (97%) diff --git a/.php_cs b/.php-cs-fixer.php similarity index 97% rename from .php_cs rename to .php-cs-fixer.php index 3ce9132..b356cf7 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -58,7 +58,6 @@ 'no_binary_string' => true, 'no_empty_phpdoc' => true, 'no_null_property_initialization' => true, - 'no_short_echo_tag' => true, 'no_superfluous_elseif' => true, 'no_unneeded_curly_braces' => true, 'no_useless_else' => true, @@ -66,7 +65,6 @@ 'ordered_class_elements' => true, 'ordered_imports' => true, 'php_unit_internal_class' => true, - 'php_unit_ordered_covers' => true, 'php_unit_test_class_requires_covers' => true, 'phpdoc_add_missing_param_annotation' => true, 'phpdoc_order' => true, @@ -113,7 +111,7 @@ ->ignoreDotFiles(true) ->ignoreVCS(true); -return \PhpCsFixer\Config::create() +return (new \PhpCsFixer\Config()) ->setFinder($finder) ->setRules($rules) ->setLineEnding("\n") diff --git a/composer.json b/composer.json index 8b14568..3d44d4e 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ } }, "scripts": { - "fixer": "php-cs-fixer fix --show-progress=estimating --verbose --ansi", + "fixer": "php-cs-fixer fix --show-progress=dots --verbose --ansi", "test": "@php tests/v2/test.php --ansi", "bf": "blackfire run php tests/v2/test.php --ansi", "assets": [ diff --git a/composer.lock b/composer.lock index 7dc3f1c..4ff9595 100644 --- a/composer.lock +++ b/composer.lock @@ -116,16 +116,16 @@ }, { "name": "symfony/css-selector", - "version": "v5.2.4", + "version": "v5.2.7", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "f65f217b3314504a1ec99c2d6ef69016bb13490f" + "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/f65f217b3314504a1ec99c2d6ef69016bb13490f", - "reference": "f65f217b3314504a1ec99c2d6ef69016bb13490f", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/59a684f5ac454f066ecbe6daecce6719aed283fb", + "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb", "shasum": "" }, "require": { @@ -161,7 +161,7 @@ "description": "Converts CSS selectors to XPath expressions", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/css-selector/tree/v5.2.4" + "source": "https://github.com/symfony/css-selector/tree/v5.3.0-BETA1" }, "funding": [ { @@ -177,20 +177,20 @@ "type": "tidelift" } ], - "time": "2021-01-27T10:01:46+00:00" + "time": "2021-04-07T16:07:52+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v2.2.0", + "version": "v2.4.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "5fa56b4074d1ae755beb55617ddafe6f5d78f665" + "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5fa56b4074d1ae755beb55617ddafe6f5d78f665", - "reference": "5fa56b4074d1ae755beb55617ddafe6f5d78f665", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627", + "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627", "shasum": "" }, "require": { @@ -199,7 +199,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-main": "2.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -228,7 +228,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/master" + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0" }, "funding": [ { @@ -244,7 +244,7 @@ "type": "tidelift" } ], - "time": "2020-09-07T11:33:47+00:00" + "time": "2021-03-23T23:28:01+00:00" }, { "name": "symfony/options-resolver", @@ -642,16 +642,16 @@ }, { "name": "composer/xdebug-handler", - "version": "1.4.6", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "f27e06cd9675801df441b3656569b328e04aa37c" + "reference": "964adcdd3a28bf9ed5d9ac6450064e0d71ed7496" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/f27e06cd9675801df441b3656569b328e04aa37c", - "reference": "f27e06cd9675801df441b3656569b328e04aa37c", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/964adcdd3a28bf9ed5d9ac6450064e0d71ed7496", + "reference": "964adcdd3a28bf9ed5d9ac6450064e0d71ed7496", "shasum": "" }, "require": { @@ -686,7 +686,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/1.4.6" + "source": "https://github.com/composer/xdebug-handler/tree/2.0.1" }, "funding": [ { @@ -702,32 +702,34 @@ "type": "tidelift" } ], - "time": "2021-03-25T17:01:18+00:00" + "time": "2021-05-05T19:37:51+00:00" }, { "name": "doctrine/annotations", - "version": "1.12.1", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "b17c5014ef81d212ac539f07a1001832df1b6d3b" + "reference": "03cb2123a67d4be806554fe670d0adc298199808" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/b17c5014ef81d212ac539f07a1001832df1b6d3b", - "reference": "b17c5014ef81d212ac539f07a1001832df1b6d3b", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/03cb2123a67d4be806554fe670d0adc298199808", + "reference": "03cb2123a67d4be806554fe670d0adc298199808", "shasum": "" }, "require": { "doctrine/lexer": "1.*", "ext-tokenizer": "*", - "php": "^7.1 || ^8.0" + "php": "^7.1 || ^8.0", + "psr/cache": "^1 || ^2 || ^3" }, "require-dev": { - "doctrine/cache": "1.*", + "doctrine/cache": "^1.11 || ^2.0", "doctrine/coding-standard": "^6.0 || ^8.1", "phpstan/phpstan": "^0.12.20", - "phpunit/phpunit": "^7.5 || ^9.1.5" + "phpunit/phpunit": "^7.5 || ^9.1.5", + "symfony/cache": "^4.4 || ^5.2" }, "type": "library", "autoload": { @@ -770,9 +772,9 @@ ], "support": { "issues": "https://github.com/doctrine/annotations/issues", - "source": "https://github.com/doctrine/annotations/tree/1.12.1" + "source": "https://github.com/doctrine/annotations/tree/1.13.0" }, - "time": "2021-02-21T21:00:45+00:00" + "time": "2021-04-29T07:39:39+00:00" }, { "name": "doctrine/lexer", @@ -856,21 +858,21 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v2.18.5", + "version": "v2.19.0", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "e0f6d05c8b157f50029ca6c65c19ed2694f475bf" + "reference": "d5b8a9d852b292c2f8a035200fa6844b1f82300b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/e0f6d05c8b157f50029ca6c65c19ed2694f475bf", - "reference": "e0f6d05c8b157f50029ca6c65c19ed2694f475bf", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/d5b8a9d852b292c2f8a035200fa6844b1f82300b", + "reference": "d5b8a9d852b292c2f8a035200fa6844b1f82300b", "shasum": "" }, "require": { "composer/semver": "^1.4 || ^2.0 || ^3.0", - "composer/xdebug-handler": "^1.2", + "composer/xdebug-handler": "^1.2 || ^2.0", "doctrine/annotations": "^1.2", "ext-json": "*", "ext-tokenizer": "*", @@ -913,6 +915,11 @@ "php-cs-fixer" ], "type": "application", + "extra": { + "branch-alias": { + "dev-master": "2.19-dev" + } + }, "autoload": { "psr-4": { "PhpCsFixer\\": "src/" @@ -948,7 +955,7 @@ "description": "A tool to automatically fix PHP code style", "support": { "issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues", - "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v2.18.5" + "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v2.19.0" }, "funding": [ { @@ -956,7 +963,7 @@ "type": "github" } ], - "time": "2021-04-06T18:37:33+00:00" + "time": "2021-05-03T21:43:24+00:00" }, { "name": "php-cs-fixer/diff", @@ -1013,6 +1020,55 @@ }, "time": "2020-10-14T08:39:05+00:00" }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "support": { + "source": "https://github.com/php-fig/cache/tree/master" + }, + "time": "2016-08-06T20:24:11+00:00" + }, { "name": "psr/container", "version": "1.1.1", @@ -1113,16 +1169,16 @@ }, { "name": "psr/log", - "version": "1.1.3", + "version": "1.1.4", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", "shasum": "" }, "require": { @@ -1146,7 +1202,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for logging libraries", @@ -1157,22 +1213,22 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.3" + "source": "https://github.com/php-fig/log/tree/1.1.4" }, - "time": "2020-03-23T09:12:05+00:00" + "time": "2021-05-03T11:20:27+00:00" }, { "name": "symfony/console", - "version": "v5.2.6", + "version": "v5.2.8", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "35f039df40a3b335ebf310f244cb242b3a83ac8d" + "reference": "864568fdc0208b3eba3638b6000b69d2386e6768" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/35f039df40a3b335ebf310f244cb242b3a83ac8d", - "reference": "35f039df40a3b335ebf310f244cb242b3a83ac8d", + "url": "https://api.github.com/repos/symfony/console/zipball/864568fdc0208b3eba3638b6000b69d2386e6768", + "reference": "864568fdc0208b3eba3638b6000b69d2386e6768", "shasum": "" }, "require": { @@ -1240,7 +1296,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.2.6" + "source": "https://github.com/symfony/console/tree/v5.2.8" }, "funding": [ { @@ -1256,7 +1312,7 @@ "type": "tidelift" } ], - "time": "2021-03-28T09:42:18+00:00" + "time": "2021-05-11T15:45:21+00:00" }, { "name": "symfony/event-dispatcher", @@ -1345,16 +1401,16 @@ }, { "name": "symfony/event-dispatcher-contracts", - "version": "v2.2.0", + "version": "v2.4.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "0ba7d54483095a198fa51781bc608d17e84dffa2" + "reference": "69fee1ad2332a7cbab3aca13591953da9cdb7a11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/0ba7d54483095a198fa51781bc608d17e84dffa2", - "reference": "0ba7d54483095a198fa51781bc608d17e84dffa2", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/69fee1ad2332a7cbab3aca13591953da9cdb7a11", + "reference": "69fee1ad2332a7cbab3aca13591953da9cdb7a11", "shasum": "" }, "require": { @@ -1367,7 +1423,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-main": "2.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -1404,7 +1460,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v2.2.0" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v2.4.0" }, "funding": [ { @@ -1420,20 +1476,20 @@ "type": "tidelift" } ], - "time": "2020-09-07T11:33:47+00:00" + "time": "2021-03-23T23:28:01+00:00" }, { "name": "symfony/filesystem", - "version": "v5.2.6", + "version": "v5.2.7", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "8c86a82f51658188119e62cff0a050a12d09836f" + "reference": "056e92acc21d977c37e6ea8e97374b2a6c8551b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/8c86a82f51658188119e62cff0a050a12d09836f", - "reference": "8c86a82f51658188119e62cff0a050a12d09836f", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/056e92acc21d977c37e6ea8e97374b2a6c8551b0", + "reference": "056e92acc21d977c37e6ea8e97374b2a6c8551b0", "shasum": "" }, "require": { @@ -1466,7 +1522,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.2.6" + "source": "https://github.com/symfony/filesystem/tree/v5.2.7" }, "funding": [ { @@ -1482,20 +1538,20 @@ "type": "tidelift" } ], - "time": "2021-03-28T14:30:26+00:00" + "time": "2021-04-01T10:42:13+00:00" }, { "name": "symfony/finder", - "version": "v5.2.4", + "version": "v5.2.8", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "0d639a0943822626290d169965804f79400e6a04" + "reference": "eccb8be70d7a6a2230d05f6ecede40f3fdd9e252" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/0d639a0943822626290d169965804f79400e6a04", - "reference": "0d639a0943822626290d169965804f79400e6a04", + "url": "https://api.github.com/repos/symfony/finder/zipball/eccb8be70d7a6a2230d05f6ecede40f3fdd9e252", + "reference": "eccb8be70d7a6a2230d05f6ecede40f3fdd9e252", "shasum": "" }, "require": { @@ -1527,7 +1583,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.2.4" + "source": "https://github.com/symfony/finder/tree/v5.2.8" }, "funding": [ { @@ -1543,7 +1599,7 @@ "type": "tidelift" } ], - "time": "2021-02-15T18:55:04+00:00" + "time": "2021-05-10T14:39:23+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1935,16 +1991,16 @@ }, { "name": "symfony/process", - "version": "v5.2.4", + "version": "v5.2.7", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "313a38f09c77fbcdc1d223e57d368cea76a2fd2f" + "reference": "98cb8eeb72e55d4196dd1e36f1f16e7b3a9a088e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/313a38f09c77fbcdc1d223e57d368cea76a2fd2f", - "reference": "313a38f09c77fbcdc1d223e57d368cea76a2fd2f", + "url": "https://api.github.com/repos/symfony/process/zipball/98cb8eeb72e55d4196dd1e36f1f16e7b3a9a088e", + "reference": "98cb8eeb72e55d4196dd1e36f1f16e7b3a9a088e", "shasum": "" }, "require": { @@ -1977,7 +2033,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v5.2.4" + "source": "https://github.com/symfony/process/tree/v5.3.0-BETA1" }, "funding": [ { @@ -1993,25 +2049,25 @@ "type": "tidelift" } ], - "time": "2021-01-27T10:15:41+00:00" + "time": "2021-04-08T10:27:02+00:00" }, { "name": "symfony/service-contracts", - "version": "v2.2.0", + "version": "v2.4.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1" + "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/d15da7ba4957ffb8f1747218be9e1a121fd298a1", - "reference": "d15da7ba4957ffb8f1747218be9e1a121fd298a1", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb", + "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb", "shasum": "" }, "require": { "php": ">=7.2.5", - "psr/container": "^1.0" + "psr/container": "^1.1" }, "suggest": { "symfony/service-implementation": "" @@ -2019,7 +2075,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-main": "2.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -2056,7 +2112,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/master" + "source": "https://github.com/symfony/service-contracts/tree/v2.4.0" }, "funding": [ { @@ -2072,20 +2128,20 @@ "type": "tidelift" } ], - "time": "2020-09-07T11:33:47+00:00" + "time": "2021-04-01T10:43:52+00:00" }, { "name": "symfony/stopwatch", - "version": "v5.2.4", + "version": "v5.2.7", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "b12274acfab9d9850c52583d136a24398cdf1a0c" + "reference": "d99310c33e833def36419c284f60e8027d359678" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/b12274acfab9d9850c52583d136a24398cdf1a0c", - "reference": "b12274acfab9d9850c52583d136a24398cdf1a0c", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/d99310c33e833def36419c284f60e8027d359678", + "reference": "d99310c33e833def36419c284f60e8027d359678", "shasum": "" }, "require": { @@ -2118,7 +2174,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v5.2.4" + "source": "https://github.com/symfony/stopwatch/tree/v5.3.0-BETA1" }, "funding": [ { @@ -2134,20 +2190,20 @@ "type": "tidelift" } ], - "time": "2021-01-27T10:15:41+00:00" + "time": "2021-03-29T15:28:41+00:00" }, { "name": "symfony/string", - "version": "v5.2.6", + "version": "v5.2.8", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572" + "reference": "01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572", - "reference": "ad0bd91bce2054103f5eaa18ebeba8d3bc2a0572", + "url": "https://api.github.com/repos/symfony/string/zipball/01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db", + "reference": "01b35eb64cac8467c3f94cd0ce2d0d376bb7d1db", "shasum": "" }, "require": { @@ -2201,7 +2257,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.2.6" + "source": "https://github.com/symfony/string/tree/v5.2.8" }, "funding": [ { @@ -2217,7 +2273,7 @@ "type": "tidelift" } ], - "time": "2021-03-17T17:12:15+00:00" + "time": "2021-05-10T14:56:10+00:00" } ], "aliases": [], diff --git a/src/Elements/CommonDomTraits.php b/src/Elements/CommonDomTraits.php index cddb923..c94bed2 100644 --- a/src/Elements/CommonDomTraits.php +++ b/src/Elements/CommonDomTraits.php @@ -316,7 +316,7 @@ private function _pushAttrValue($name, $value, $addValue = false) /** * @internal * - * @param \DOMNode|string $input + * @param \DOMNode|string $input * @return \DOMNode */ private function _safeNode($input) diff --git a/tests/helpers.php b/tests/helpers.php index 8105980..4ed530c 100644 --- a/tests/helpers.php +++ b/tests/helpers.php @@ -38,7 +38,7 @@ function debug() } if (!empty($msgs)) { - echo ($text . implode("\n", $msgs)) . "\n"; + echo($text . implode("\n", $msgs)) . "\n"; } $last_time = microtime(true); From 7993ebceea48ace1c2d90f75a4abbd4c9d5c2d55 Mon Sep 17 00:00:00 2001 From: shinsenter <2082119+shinsenter@users.noreply.github.com> Date: Sat, 15 May 2021 11:09:17 +0900 Subject: [PATCH 3/5] Small updates --- README.md | 2 +- package-lock.json | 18 +++++++++++------- package.json | 4 ++-- public/lib/defer.min.js | 2 +- public/lib/defer_plus.min.js | 2 +- src/Helpers/DeferConstant.php | 2 +- src/Helpers/DeferOptions.php | 2 +- src/Resolvers/LinkResolver.php | 8 ++++---- src/Resolvers/ScriptResolver.php | 18 ++++++++---------- 9 files changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index a638daf..cf0b253 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ $options = [ 'manually_add_deferjs' => false, // URL to defer.js javascript file. - // Default: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js + // Default: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.2/dist/defer_plus.min.js 'deferjs_src' => \AppSeeds\DeferConstant::SRC_DEFERJS_CDN, // URL to javascript contains fixes. diff --git a/package-lock.json b/package-lock.json index a5dd353..b0084ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,13 +6,13 @@ "": { "license": "MIT", "dependencies": { - "@shinsenter/defer.js": "^2.4.1" + "@shinsenter/defer.js": "^2.4.2" } }, "node_modules/@shinsenter/defer.js": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@shinsenter/defer.js/-/defer.js-2.4.1.tgz", - "integrity": "sha512-/WFC4OI+kCUqEaSy3PuFCFsWe0TdcAWWx4eztptpqaGENZHViOvJyqnN7fEoL3ZNLxDQWQPadZNXlUUNdnioyw==", + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@shinsenter/defer.js/-/defer.js-2.4.2.tgz", + "integrity": "sha512-hZkySx293V5zqZb1aEc4ARm3v2ONj3ufPtmZRJzZMzmTNfmpdcVjfcBqgm09vf5ja1lH1NOLE5zxYF4KIwn7yQ==", "funding": [ { "type": "github", @@ -26,14 +26,18 @@ "type": "patreon", "url": "https://www.patreon.com/shinsenter" } + ], + "license": "MIT", + "workspaces": [ + "dist/" ] } }, "dependencies": { "@shinsenter/defer.js": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@shinsenter/defer.js/-/defer.js-2.4.1.tgz", - "integrity": "sha512-/WFC4OI+kCUqEaSy3PuFCFsWe0TdcAWWx4eztptpqaGENZHViOvJyqnN7fEoL3ZNLxDQWQPadZNXlUUNdnioyw==" + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@shinsenter/defer.js/-/defer.js-2.4.2.tgz", + "integrity": "sha512-hZkySx293V5zqZb1aEc4ARm3v2ONj3ufPtmZRJzZMzmTNfmpdcVjfcBqgm09vf5ja1lH1NOLE5zxYF4KIwn7yQ==" } } } diff --git a/package.json b/package.json index 0cc1e7c..b3b053f 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,12 @@ "author": "Mai Nhut Tan ", "license": "MIT", "dependencies": { - "@shinsenter/defer.js": "^2.4.1" + "@shinsenter/defer.js": "^2.4.2" }, "scripts": { "cleanup": "rm -rf ./node_modules package-lock.json", "tools": "npm -g i eslint js-beautify uglify-js clean-css-cli", - "pull": "npm run cleanup && npm run tools && npm i --prod", + "pull": "npm run cleanup && npm run tools && npm i --prod && npm audit fix", "copy": "cp -p ./node_modules/@shinsenter/defer.js/dist/*.js ./public/lib/", "lint": "eslint --config assets/.eslintrc --ext .js assets --fix", "js": "uglifyjs --config-file assets/.uglifyjs -o public/helpers.min.js assets/helpers.js", diff --git a/public/lib/defer.min.js b/public/lib/defer.min.js index 3a194cc..584e7ca 100644 --- a/public/lib/defer.min.js +++ b/public/lib/defer.min.js @@ -1,2 +1,2 @@ /*@shinsenter/defer.js*/ -!function(r,i,t){var u,o=/^data-(.+)/,a='IntersectionObserver',c=/p/.test(i.readyState),s=[],f=s.slice,l='lazied',e='load',n='pageshow',d='forEach',h='hasAttribute',m='shift';function v(e){i.head.appendChild(e)}function p(e,n){f.call(e.attributes)[d](n)}function y(e,n,t,o){return o=(o=n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function b(e,n){return f.call((n||i).querySelectorAll(e))}function I(t){b('source',t)[d](I),p(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e in t&&t[e]()}function g(e){u(function(o){o=b(e||'[type=deferjs]'),function e(n,t){(n=o[m]())&&(n.parentNode.removeChild(n),(t=y(n.nodeName)).text=n.text,p(n,function(e){'type'!=e.name&&(t[e.name]=e.value)}),t.src&&!t[h]('async')?(t.onload=t.onerror=e,v(t)):(v(t),e()))}()})}(u=function(e,n){c?t(e,n):s.push(e,n)}).all=g,u.js=function(n,t,e,o){u(function(e){(e=y('SCRIPT',t,o)).src=n,v(e)},e)},u.css=function(n,t,e,o){u(function(e){(e=y('LINK',t,o)).rel='stylesheet',e.href=n,v(e)},e)},u.dom=function(e,n,t,o,i){function c(e){o&&!1===o(e)||(I(e),t&&(e.className+=' '+t))}u(function(t){t=a in r&&new r[a](function(e){e[d](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),c(n))})},i),b(e||'[data-src]')[d](function(e){e[h](l)||(e.setAttribute(l,''),t?t.observe(e):c(e))})},n)},u.reveal=I,r.Defer=u,r.addEventListener('on'+n in r?n:e,function(){for(g();s[0];t(s[m](),s[m]()))c=1})}(this,document,setTimeout); \ No newline at end of file +!function(r,i,t){var u,o=/^data-(.+)/,a='IntersectionObserver',c=/p/.test(i.readyState),s=[],f=s.slice,l='lazied',n='load',e='pageshow',d='forEach',h='hasAttribute',m='shift';function v(e){i.head.appendChild(e)}function p(e,n){f.call(e.attributes)[d](n)}function y(e,n,t,o){return o=(o=n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function b(e,n){return f.call((n||i).querySelectorAll(e))}function I(t,e){b('source',t)[d](I),p(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e&&(t.className+=' '+e),n in t&&t[n]()}function g(e){u(function(o){o=b(e||'[type=deferjs]'),function e(n,t){(n=o[m]())&&(n.parentNode.removeChild(n),(t=y(n.nodeName)).text=n.text,p(n,function(e){'type'!=e.name&&(t[e.name]=e.value)}),t.src&&!t[h]('async')?(t.onload=t.onerror=e,v(t)):(v(t),e()))}()})}(u=function(e,n){c?t(e,n):s.push(e,n)}).all=g,u.js=function(n,t,e,o){u(function(e){(e=y('SCRIPT',t,o)).src=n,v(e)},e)},u.css=function(n,t,e,o){u(function(e){(e=y('LINK',t,o)).rel='stylesheet',e.href=n,v(e)},e)},u.dom=function(e,n,t,o,i){function c(e){o&&!1===o(e)||I(e,t)}u(function(t){t=a in r&&new r[a](function(e){e[d](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),c(n))})},i),b(e||'[data-src]')[d](function(e){e[h](l)||(e.setAttribute(l,''),t?t.observe(e):c(e))})},n)},u.reveal=I,r.Defer=u,r.addEventListener('on'+e in r?e:n,function(){for(g();s[0];t(s[m](),s[m]()))c=1})}(this,document,setTimeout); \ No newline at end of file diff --git a/public/lib/defer_plus.min.js b/public/lib/defer_plus.min.js index a4a5aed..05b8ba0 100644 --- a/public/lib/defer_plus.min.js +++ b/public/lib/defer_plus.min.js @@ -1,2 +1,2 @@ /*@shinsenter/defer.js*/ -!function(c,i,t){var f,o=/^data-(.+)/,u='IntersectionObserver',r=/p/.test(i.readyState),s=[],a=s.slice,d='lazied',e='load',n='pageshow',l='forEach',m='hasAttribute',h='shift';function p(e){i.head.appendChild(e)}function v(e,n){a.call(e.attributes)[l](n)}function y(e,n,t,o){return o=(o=n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function b(e,n){return a.call((n||i).querySelectorAll(e))}function g(t){b('source',t)[l](g),v(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e in t&&t[e]()}function I(e){f(function(o){o=b(e||'[type=deferjs]'),function e(n,t){(n=o[h]())&&(n.parentNode.removeChild(n),(t=y(n.nodeName)).text=n.text,v(n,function(e){'type'!=e.name&&(t[e.name]=e.value)}),t.src&&!t[m]('async')?(t.onload=t.onerror=e,p(t)):(p(t),e()))}()})}(f=function(e,n){r?t(e,n):s.push(e,n)}).all=I,f.js=function(n,t,e,o){f(function(e){(e=y('SCRIPT',t,o)).src=n,p(e)},e)},f.css=function(n,t,e,o){f(function(e){(e=y('LINK',t,o)).rel='stylesheet',e.href=n,p(e)},e)},f.dom=function(e,n,t,o,i){function r(e){o&&!1===o(e)||(g(e),t&&(e.className+=' '+t))}f(function(t){t=u in c&&new c[u](function(e){e[l](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),r(n))})},i),b(e||'[data-src]')[l](function(e){e[m](d)||(e.setAttribute(d,''),t?t.observe(e):r(e))})},n)},f.reveal=g,c.Defer=f,c.addEventListener('on'+n in c?n:e,function(){for(I();s[0];t(s[h](),s[h]()))r=1})}(this,document,setTimeout),function(e,n){e.defer=n=e.Defer,e.deferscript=n.js,e.deferstyle=n.css,e.deferimg=e.deferiframe=n.dom}(this); \ No newline at end of file +!function(c,i,t){var f,o=/^data-(.+)/,u='IntersectionObserver',r=/p/.test(i.readyState),s=[],a=s.slice,d='lazied',n='load',e='pageshow',l='forEach',m='hasAttribute',h='shift';function p(e){i.head.appendChild(e)}function v(e,n){a.call(e.attributes)[l](n)}function y(e,n,t,o){return o=(o=n?i.getElementById(n):o)||i.createElement(e),n&&(o.id=n),t&&(o.onload=t),o}function b(e,n){return a.call((n||i).querySelectorAll(e))}function g(t,e){b('source',t)[l](g),v(t,function(e,n){(n=o.exec(e.name))&&(t[n[1]]=e.value)}),e&&(t.className+=' '+e),n in t&&t[n]()}function I(e){f(function(o){o=b(e||'[type=deferjs]'),function e(n,t){(n=o[h]())&&(n.parentNode.removeChild(n),(t=y(n.nodeName)).text=n.text,v(n,function(e){'type'!=e.name&&(t[e.name]=e.value)}),t.src&&!t[m]('async')?(t.onload=t.onerror=e,p(t)):(p(t),e()))}()})}(f=function(e,n){r?t(e,n):s.push(e,n)}).all=I,f.js=function(n,t,e,o){f(function(e){(e=y('SCRIPT',t,o)).src=n,p(e)},e)},f.css=function(n,t,e,o){f(function(e){(e=y('LINK',t,o)).rel='stylesheet',e.href=n,p(e)},e)},f.dom=function(e,n,t,o,i){function r(e){o&&!1===o(e)||g(e,t)}f(function(t){t=u in c&&new c[u](function(e){e[l](function(e,n){e.isIntersecting&&(n=e.target)&&(t.unobserve(n),r(n))})},i),b(e||'[data-src]')[l](function(e){e[m](d)||(e.setAttribute(d,''),t?t.observe(e):r(e))})},n)},f.reveal=g,c.Defer=f,c.addEventListener('on'+e in c?e:n,function(){for(I();s[0];t(s[h](),s[h]()))r=1})}(this,document,setTimeout),function(e,n){e.defer=n=e.Defer,e.deferscript=n.js,e.deferstyle=n.css,e.deferimg=e.deferiframe=n.dom}(this); \ No newline at end of file diff --git a/src/Helpers/DeferConstant.php b/src/Helpers/DeferConstant.php index 89c5605..6cf6679 100644 --- a/src/Helpers/DeferConstant.php +++ b/src/Helpers/DeferConstant.php @@ -152,7 +152,7 @@ class DeferConstant // ------------------------------------------------------------------------- // Source files - const SRC_DEFERJS_CDN = 'https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js'; + const SRC_DEFERJS_CDN = 'https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.2/dist/defer_plus.min.js'; const SRC_POLYFILL_CDN = 'https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver'; const SRC_DEFERJS_FALLBACK = DEFER_PHP_ROOT . '/public/lib/defer_plus.min.js'; const SCR_DEFERJS_CACHE = DEFER_PHP_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR; diff --git a/src/Helpers/DeferOptions.php b/src/Helpers/DeferOptions.php index 6932a56..eaef467 100644 --- a/src/Helpers/DeferOptions.php +++ b/src/Helpers/DeferOptions.php @@ -241,7 +241,7 @@ public function getWellKnown3rd($useCache = true) * 'manually_add_deferjs' => false, * * // URL to defer.js javascript file. - * // Default: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js + * // Default: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.2/dist/defer_plus.min.js * 'deferjs_src' => \AppSeeds\DeferConstant::SRC_DEFERJS_CDN, * * // URL to javascript contains fixes. diff --git a/src/Resolvers/LinkResolver.php b/src/Resolvers/LinkResolver.php index aab815f..39279fb 100644 --- a/src/Resolvers/LinkResolver.php +++ b/src/Resolvers/LinkResolver.php @@ -285,6 +285,10 @@ public function shouldLazyload() */ public function lazyload() { + // Remove lazy attributes + $this->node->removeAttribute(DeferConstant::ATTR_DEFER); + $this->node->removeAttribute(DeferConstant::ATTR_LAZY); + // Only defer when it is a CSS node // and "onload" attribute is not provided if (!$this->isCss() || @@ -294,10 +298,6 @@ public function lazyload() return false; } - // Remove lazy attributes - $this->node->removeAttribute(DeferConstant::ATTR_DEFER); - $this->node->removeAttribute(DeferConstant::ATTR_LAZY); - // Convert to preload tag $this->node->setAttribute('rel', 'preload'); $this->node->setAttribute('as', 'style'); diff --git a/src/Resolvers/ScriptResolver.php b/src/Resolvers/ScriptResolver.php index 30c9a74..effa867 100644 --- a/src/Resolvers/ScriptResolver.php +++ b/src/Resolvers/ScriptResolver.php @@ -195,16 +195,14 @@ public function shouldLazyload() */ public function lazyload() { - if ($this->isDeferJs() || - $this->isCriticalJavascript() || - $this->skipLazyloading('src')) { - return false; - } - - $lazied = true; - // Only defer for javascript if ($this->isJavascript()) { + if ($this->isDeferJs() || + $this->isCriticalJavascript() || + $this->skipLazyloading('src')) { + return false; + } + // Remove lazy attributes $this->node->removeAttribute(DeferConstant::ATTR_DEFER); $this->node->removeAttribute(DeferConstant::ATTR_LAZY); @@ -212,10 +210,10 @@ public function lazyload() // Convert to type=deferjs node $this->node->setAttribute('type', $this->options->deferjs_type_attribute); - $lazied = true; + return true; } - return $lazied; + return false; } /** From 2b37c0004fa06b7998cd08a1dc3472976cc36be6 Mon Sep 17 00:00:00 2001 From: shinsenter <2082119+shinsenter@users.noreply.github.com> Date: Thu, 20 May 2021 21:57:00 +0900 Subject: [PATCH 4/5] Defer async tags --- composer.lock | 38 ++++++++++++++++---------------- package-lock.json | 4 ---- src/Helpers/DeferConstant.php | 5 ++++- src/Resolvers/ScriptResolver.php | 28 ++++++++++++++++++++++- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/composer.lock b/composer.lock index 4ff9595..c71ee37 100644 --- a/composer.lock +++ b/composer.lock @@ -116,16 +116,16 @@ }, { "name": "symfony/css-selector", - "version": "v5.2.7", + "version": "v5.2.9", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb" + "reference": "5d5f97809015102116208b976eb2edb44b689560" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/59a684f5ac454f066ecbe6daecce6719aed283fb", - "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/5d5f97809015102116208b976eb2edb44b689560", + "reference": "5d5f97809015102116208b976eb2edb44b689560", "shasum": "" }, "require": { @@ -161,7 +161,7 @@ "description": "Converts CSS selectors to XPath expressions", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/css-selector/tree/v5.3.0-BETA1" + "source": "https://github.com/symfony/css-selector/tree/v5.2.9" }, "funding": [ { @@ -177,7 +177,7 @@ "type": "tidelift" } ], - "time": "2021-04-07T16:07:52+00:00" + "time": "2021-05-16T13:07:46+00:00" }, { "name": "symfony/deprecation-contracts", @@ -706,16 +706,16 @@ }, { "name": "doctrine/annotations", - "version": "1.13.0", + "version": "1.13.1", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "03cb2123a67d4be806554fe670d0adc298199808" + "reference": "e6e7b7d5b45a2f2abc5460cc6396480b2b1d321f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/03cb2123a67d4be806554fe670d0adc298199808", - "reference": "03cb2123a67d4be806554fe670d0adc298199808", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/e6e7b7d5b45a2f2abc5460cc6396480b2b1d321f", + "reference": "e6e7b7d5b45a2f2abc5460cc6396480b2b1d321f", "shasum": "" }, "require": { @@ -728,7 +728,7 @@ "doctrine/cache": "^1.11 || ^2.0", "doctrine/coding-standard": "^6.0 || ^8.1", "phpstan/phpstan": "^0.12.20", - "phpunit/phpunit": "^7.5 || ^9.1.5", + "phpunit/phpunit": "^7.5 || ^8.0 || ^9.1.5", "symfony/cache": "^4.4 || ^5.2" }, "type": "library", @@ -772,9 +772,9 @@ ], "support": { "issues": "https://github.com/doctrine/annotations/issues", - "source": "https://github.com/doctrine/annotations/tree/1.13.0" + "source": "https://github.com/doctrine/annotations/tree/1.13.1" }, - "time": "2021-04-29T07:39:39+00:00" + "time": "2021-05-16T18:07:53+00:00" }, { "name": "doctrine/lexer", @@ -1542,16 +1542,16 @@ }, { "name": "symfony/finder", - "version": "v5.2.8", + "version": "v5.2.9", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "eccb8be70d7a6a2230d05f6ecede40f3fdd9e252" + "reference": "ccccb9d48ca42757dd12f2ca4bf857a4e217d90d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/eccb8be70d7a6a2230d05f6ecede40f3fdd9e252", - "reference": "eccb8be70d7a6a2230d05f6ecede40f3fdd9e252", + "url": "https://api.github.com/repos/symfony/finder/zipball/ccccb9d48ca42757dd12f2ca4bf857a4e217d90d", + "reference": "ccccb9d48ca42757dd12f2ca4bf857a4e217d90d", "shasum": "" }, "require": { @@ -1583,7 +1583,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.2.8" + "source": "https://github.com/symfony/finder/tree/v5.2.9" }, "funding": [ { @@ -1599,7 +1599,7 @@ "type": "tidelift" } ], - "time": "2021-05-10T14:39:23+00:00" + "time": "2021-05-16T13:07:46+00:00" }, { "name": "symfony/polyfill-ctype", diff --git a/package-lock.json b/package-lock.json index b0084ea..b59f52f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,10 +26,6 @@ "type": "patreon", "url": "https://www.patreon.com/shinsenter" } - ], - "license": "MIT", - "workspaces": [ - "dist/" ] } }, diff --git a/src/Helpers/DeferConstant.php b/src/Helpers/DeferConstant.php index 6cf6679..397e0dc 100644 --- a/src/Helpers/DeferConstant.php +++ b/src/Helpers/DeferConstant.php @@ -50,6 +50,7 @@ class DeferConstant const ATTR_NOLAZY = 'data-nolazy'; // Attribute names to lazyload CSS element + const ATTR_ASYNC = 'async'; const ATTR_DEFER = 'defer'; const ATTR_LAZY = 'data-lazy'; @@ -179,6 +180,7 @@ class DeferConstant '.bootstrapcdn.com', '.disqus.com', '.doubleclick.net', + '.facebook.net', '.fontawesome.com', '.google-analytics.com', '.googlesyndication.com', @@ -192,8 +194,8 @@ class DeferConstant '.youtube.com', '//api.pinterest.com', '//apis.google.com', + '//b.st-hatena.com', '//cdnjs.cloudflare.com', - '//connect.facebook.net', '//disqus.com', '//fonts.googleapis.com', '//google-analytics.com', @@ -208,6 +210,7 @@ class DeferConstant '//s.yimg.', '//syndication.twitter.com', '//youtube.com', + '//www.youtube.com', 'adservice.google.', ]; } diff --git a/src/Resolvers/ScriptResolver.php b/src/Resolvers/ScriptResolver.php index effa867..9f2598d 100644 --- a/src/Resolvers/ScriptResolver.php +++ b/src/Resolvers/ScriptResolver.php @@ -140,6 +140,16 @@ public function normalize() if ($normalized != $src) { $this->node->setAttribute('src', $normalized); } + } elseif ($this->isJavascript()) { + if ($this->node->hasAttribute(DeferConstant::ATTR_ASYNC)) { + $this->node->removeAttribute(DeferConstant::ATTR_ASYNC); + $this->node->setAttribute(DeferConstant::ATTR_LAZY, 'true'); + } + + if ($this->node->hasAttribute(DeferConstant::ATTR_DEFER)) { + $this->node->removeAttribute(DeferConstant::ATTR_DEFER); + $this->node->setAttribute(DeferConstant::ATTR_LAZY, 'true'); + } } if ($this->isJavascript()) { @@ -190,6 +200,22 @@ public function shouldLazyload() && ($this->hasLazyloadFlag() || $this->isThirdParty()); } + /** + * Check if the node contains "data-lazy" or "defer" attribute + * + * @return bool + */ + public function hasLazyloadFlag() + { + if ($this->node->hasAttribute(DeferConstant::ATTR_DEFER) + || $this->node->hasAttribute(DeferConstant::ATTR_ASYNC) + || $this->node->hasAttribute(DeferConstant::ATTR_LAZY)) { + return true; + } + + return false; + } + /** * {@inheritdoc} */ @@ -247,7 +273,7 @@ public function isThirdParty() public function getPreloadNode() { if ($this->isSrcJavascript() - && ($this->isThirdParty() || !$this->node->hasAttribute('async'))) { + && !$this->node->hasAttribute(DeferConstant::ATTR_ASYNC)) { $preload = $this->newNode('link', [ 'rel' => LinkResolver::PRELOAD, 'as' => 'script', From 1559d51b0dee22069dc778eb9763431c67689d1a Mon Sep 17 00:00:00 2001 From: Shin <2082119+shinsenter@users.noreply.github.com> Date: Fri, 21 May 2021 12:01:34 +0900 Subject: [PATCH 5/5] Fixed pcre.backtrack_limit --- src/Defer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Defer.php b/src/Defer.php index d75430b..338f110 100644 --- a/src/Defer.php +++ b/src/Defer.php @@ -358,7 +358,7 @@ public function optionArray() */ private function isFullPageHtml($html) { - return preg_match('/<\!DOCTYPE.+/is', $html); + return preg_match('/<\!DOCTYPE.+html.+