Skip to content

Commit

Permalink
:closes: Add hints to defer wpr script --#6091
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Jul 29, 2024
1 parent 9fe189b commit a7bb5db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion inc/Engine/Optimization/DeferJS/DeferJS.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function defer_js( string $html ): string {
continue;
}

$deferred_tag = str_replace( '>', ' defer>', $tag[0] );
$deferred_tag = str_replace( '>', ' data-rocket-defer defer>', $tag[0] );
$html = str_replace( $tag[0], $deferred_tag, $html );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
;

$expected = <<<HTML
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" defer></script>
<script src="http://example.org/wp-content/plugins/hello-world/script.js" id="hello-script" defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" defer></script>
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" data-rocket-defer defer></script>
<script src="http://example.org/wp-content/plugins/hello-world/script.js" id="hello-script" data-rocket-defer defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" data-rocket-defer defer></script>
<script integrity="sha512-VtmdOFNyOniRUIHzkfL4GAe+yuAhoWzJIWYW/9elcd+7zNu12OKscWFIe9PRQ6VBy4djrwGVzK6MLD3oTpLpRQ==" crossorigin="anonymous" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.js" defer></script>
<script data-cfasync="false" src="/javascript.js" defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" defer></script>
<script data-cfasync="false" src="/javascript.js" data-rocket-defer defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" data-rocket-defer defer></script>
HTML
;

$expected_exclusion = <<<HTML
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" defer></script>
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" data-rocket-defer defer></script>
<script src="http://example.org/wp-content/plugins/hello-world/script.js" id="hello-script"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" data-rocket-defer defer></script>
<script integrity="sha512-VtmdOFNyOniRUIHzkfL4GAe+yuAhoWzJIWYW/9elcd+7zNu12OKscWFIe9PRQ6VBy4djrwGVzK6MLD3oTpLpRQ==" crossorigin="anonymous" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.js" defer></script>
<script data-cfasync="false" src="/javascript.js" defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" defer></script>
<script data-cfasync="false" src="/javascript.js" data-rocket-defer defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" data-rocket-defer defer></script>
HTML
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function newContent() {
;

$expected = <<<HTML
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" defer></script>
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" data-rocket-defer defer></script>
<script src="http://example.org/wp-content/plugins/ewww-image-optimizer/includes/check-webp.js"></script>
<script src="http://example.org/wp-content/plugins/ewww-image-optimizer/includes/check-webp.min.js"></script>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
;

$expected = <<<HTML
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" defer></script>
<script src="http://example.org/wp-content/plugins/hello-world/script.js" id="hello-script" defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" defer></script>
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" data-rocket-defer defer></script>
<script src="http://example.org/wp-content/plugins/hello-world/script.js" id="hello-script" data-rocket-defer defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" data-rocket-defer defer></script>
<script integrity="sha512-VtmdOFNyOniRUIHzkfL4GAe+yuAhoWzJIWYW/9elcd+7zNu12OKscWFIe9PRQ6VBy4djrwGVzK6MLD3oTpLpRQ==" crossorigin="anonymous" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.js" defer></script>
<script data-cfasync="false" src="/javascript.js" defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" defer></script>
<script data-cfasync="false" src="/javascript.js" data-rocket-defer defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" data-rocket-defer defer></script>
<script src="http://example.org/wp-content/plugins/ewww-image-optimizer/includes/check-webp.js"></script>
<script src="http://example.org/wp-content/plugins/ewww-image-optimizer/includes/check-webp.min.js"></script>
<script>alert('ewww_webp_supported');</script>
HTML
;

$expected_exclusion = <<<HTML
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" defer></script>
<script src="http://example.org/wp-includes/js/jquery/jquery.js?v=3.1.15" id="jquery-core" data-rocket-defer defer></script>
<script src="http://example.org/wp-content/plugins/hello-world/script.js" id="hello-script"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_API_KEY&#038;language=en&#038;ver=1" data-rocket-defer defer></script>
<script integrity="sha512-VtmdOFNyOniRUIHzkfL4GAe+yuAhoWzJIWYW/9elcd+7zNu12OKscWFIe9PRQ6VBy4djrwGVzK6MLD3oTpLpRQ==" crossorigin="anonymous" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.js" defer></script>
<script data-cfasync="false" src="/javascript.js" defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" defer></script>
<script data-cfasync="false" src="/javascript.js" data-rocket-defer defer></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51f58c4473f92506" data-rocket-defer defer></script>
<script src="http://example.org/wp-content/plugins/ewww-image-optimizer/includes/check-webp.js"></script>
<script src="http://example.org/wp-content/plugins/ewww-image-optimizer/includes/check-webp.min.js"></script>
<script>alert('ewww_webp_supported');</script>
Expand Down

0 comments on commit a7bb5db

Please sign in to comment.