File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
plugins/optimization-detective/tests/test-cases/preload-link Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ < html lang ="en ">
2
+ < head >
3
+ < meta charset ="utf-8 ">
4
+ < title > ...</ title >
5
+ </ head >
6
+ < body >
7
+ < div id ="page ">
8
+ < img src ="https://example.com/image.jpg " alt ="" width ="100 " height ="100 ">
9
+ </ div >
10
+ </ body >
11
+ </ html >
Original file line number Diff line number Diff line change
1
+ < html lang ="en ">
2
+ < head >
3
+ < meta charset ="utf-8 ">
4
+ < title > ...</ title >
5
+ < link data-od-added-tag rel ="preload " as ="image " href ="https://example.com/image.jpg ">
6
+ </ head >
7
+ < body >
8
+ < div id ="page ">
9
+ < img data-od-xpath ="/HTML/BODY/DIV/*[1][self::IMG] " src ="https://example.com/image.jpg " alt ="" width ="100 " height ="100 ">
10
+ </ div >
11
+ < script type ="module "> /* import detect ... */ </ script >
12
+ </ body >
13
+ </ html >
Original file line number Diff line number Diff line change
1
+ <?php
2
+ return static function (): void {
3
+
4
+ add_action (
5
+ 'od_register_tag_visitors ' ,
6
+ static function ( OD_Tag_Visitor_Registry $ registry ): void {
7
+ $ registry ->register (
8
+ 'img-preload ' ,
9
+ static function ( OD_Tag_Visitor_Context $ context ): bool {
10
+ if ( 'IMG ' === $ context ->processor ->get_tag () ) {
11
+ $ context ->link_collection ->add_link (
12
+ array (
13
+ 'rel ' => 'preload ' ,
14
+ 'as ' => 'image ' ,
15
+ 'href ' => $ context ->processor ->get_attribute ( 'src ' ),
16
+ )
17
+ );
18
+ }
19
+ return false ;
20
+ }
21
+ );
22
+ }
23
+ );
24
+ };
You can’t perform that action at this time.
0 commit comments