@@ -34,6 +34,7 @@ private function extract_jsonld_schema(&$html) {
3434 /**
3535 * Extract all link and script tags from head section (everything except JSON-LD schema)
3636 * Prioritizes font links to ensure they load first
37+ * Adds Nitropack exclusion attributes to prevent optimization issues
3738 */
3839 private function extract_head_resources ($ html ) {
3940 $ font_links = '' ;
@@ -49,8 +50,17 @@ private function extract_head_resources($html) {
4950 foreach ($ link_matches [0 ] as $ link ) {
5051 // Prioritize font links (Google Fonts, etc.)
5152 if (preg_match ('/fonts\.(googleapis|gstatic)/i ' , $ link ) || preg_match ('/font/i ' , $ link )) {
53+ // Add Nitropack exclusion attributes to font links to prevent optimization issues
54+ if (strpos ($ link , 'data-nitro-exclude ' ) === false ) {
55+ // Insert data-nitro attributes before closing >
56+ $ link = str_replace ('> ' , ' data-nitro-exclude="all" data-nitro-ignore="true"> ' , $ link );
57+ }
5258 $ font_links .= $ link . "\n" ;
5359 } else {
60+ // Add Nitropack exclusion to other stylesheets as well
61+ if (strpos ($ link , 'rel="stylesheet" ' ) !== false && strpos ($ link , 'data-nitro-exclude ' ) === false ) {
62+ $ link = str_replace ('> ' , ' data-nitro-exclude="all" data-nitro-ignore="true"> ' , $ link );
63+ }
5464 $ other_links .= $ link . "\n" ;
5565 }
5666 }
@@ -129,7 +139,9 @@ public function init($atts) {
129139 echo $ jsonld_schema ;
130140 }
131141
132- // 2. Head resources (links and scripts)
142+ // 2. Head resources (links and scripts) - must come before div with "all: initial"
143+ // Font links need to load before the CSS reset applies
144+ // Note: Links and scripts in body are valid HTML5, but should be output early
133145 if (!empty ($ head_resources )) {
134146 echo $ head_resources ;
135147 }
0 commit comments