@@ -16,6 +16,24 @@ class AbstractLizmapHtmlResponse extends jResponseHtml
16
16
{
17
17
protected $ CSPPropName = 'mapCSPHeader ' ;
18
18
19
+ protected function outputJsScriptTag ($ fileUrl , $ scriptParams )
20
+ {
21
+ echo '<link rel="preload" href=" ' ,htmlspecialchars ($ fileUrl ),'" as="script" ' ,$ this ->_endTag ;
22
+ parent ::outputJsScriptTag ($ fileUrl , $ scriptParams );
23
+ }
24
+
25
+ protected function outputCssLinkTag ($ fileUrl , $ cssParams )
26
+ {
27
+ echo '<link rel="preload" href=" ' ,htmlspecialchars ($ fileUrl ),'" as="style" ' ,$ this ->_endTag ;
28
+ parent ::outputCssLinkTag ($ fileUrl , $ cssParams );
29
+ }
30
+
31
+ protected function outputIconLinkTag ($ fileUrl , $ iconParams )
32
+ {
33
+ echo '<link rel="preload" href=" ' ,htmlspecialchars ($ fileUrl ),'" as="image" ' ,$ this ->_endTag ;
34
+ parent ::outputIconLinkTag ($ fileUrl , $ iconParams );
35
+ }
36
+
19
37
protected function prepareHeadContent ()
20
38
{
21
39
$ bp = jApp::urlBasePath ();
@@ -64,8 +82,44 @@ public function addJsVariables(array $variables)
64
82
$ this ->jsVarData = array_merge ($ this ->jsVarData , $ variables );
65
83
}
66
84
85
+ protected $ preloadLink = array ();
86
+
87
+ public function addPreloadLink ($ href , $ as , $ type = null )
88
+ {
89
+ $ this ->preloadLink [] = array (
90
+ 'href ' => $ href ,
91
+ 'as ' => $ as ,
92
+ 'type ' => $ type ,
93
+ );
94
+ }
95
+
67
96
protected function doAfterActions ()
68
97
{
69
- $ this ->addHeadContent ('<script id="lizmap-vars" type="application/json"> ' .json_encode ($ this ->jsVarData ).'</script> ' );
98
+ $ this ->addHeadContent ('<!-- Start preload --> ' );
99
+ // Preload links
100
+ // css link
101
+ /*foreach ($this->webAssetsSelection->getCssLinks() as $src) {
102
+ $this->addHeadContent('<link rel="preload" href="'.$src[0].'" as="style">');
103
+ }
104
+ foreach ($this->_CSSLink as $src => $params) {
105
+ $this->addHeadContent('<link rel="preload" href="'.$src.'" as="style">');
106
+ }
107
+ // js link
108
+ foreach ($this->webAssetsSelection->getJsLinks() as $src) {
109
+ $this->addHeadContent('<link rel="preload" href="'.$src[0].'" as="script">');
110
+ }
111
+ foreach ($this->_JSLink as $src => $params) {
112
+ $this->addHeadContent('<link rel="preload" href="'.$src.'" as="script">');
113
+ }
114
+ // others links
115
+ foreach ($this->_Link as $href => $params) {
116
+ $this->addHeadContent('<link rel="preload" href="'.$href.'" as="'.$params[0].'"'.($params[1] ? ' type="'.$params[1].'"' : '').'>');
117
+ }*/
118
+ // other preload links
119
+ foreach ($ this ->preloadLink as $ link ) {
120
+ $ this ->addHeadContent ('<link rel="preload" href=" ' .$ link ['href ' ].'" as=" ' .$ link ['as ' ].'" ' .($ link ['type ' ] ? ' type=" ' .$ link ['type ' ].'" ' : '' ).'> ' );
121
+ }
122
+ $ this ->addHeadContent ('<!-- End preload --> ' );
123
+ $ this ->addHeadContent ('<script id="lizmap-vars" type="application/json"> ' .json_encode ($ this ->jsVarData ).'</script> ' ."\n" );
70
124
}
71
125
}
0 commit comments