Skip to content

Commit

Permalink
:closes: Add hints to scripts deferred by WPR --#6091
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Jul 29, 2024
1 parent 905d862 commit 0041008
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 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

0 comments on commit 0041008

Please sign in to comment.