मुझे रिले टैग को बदलने की जरूरत है। मूल कोड:
<link href="style.css" rel="stylesheet" />
आवश्यक कोड:
<link href="style.css" rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'" />
<noscript><link href="style.css" rel="stylesheet" /></noscript>
-2
jazzfriends
26 पद 2018, 12:16
1 उत्तर
सबसे बढ़िया उत्तर
शायद एक नियमित अभिव्यक्ति एक आसान समाधान प्रतीत होगा, लेकिन यह बहुत सारे नुकसान छुपा सकता है। इस मामले में मैं आवश्यक परिवर्तन करने के लिए डोम का उपयोग करूंगा।
$html = '<link href="style.css" rel="stylesheet">';
libxml_use_internal_errors(true);
$dom = new DomDocument();
$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//link[@rel="stylesheet"]') as $link) {
// Insert a copy of link inside the <noscript>
$noscript = $dom->createElement('noscript');
$noscript->appendChild($link->cloneNode(true));
$link->parentNode->insertBefore($noscript, $link->nextSibling);
// Modify the link attributes
$link->setAttribute('rel', 'preload');
$link->setAttribute('as', 'style');
$link->setAttribute('onload', "this.onload=null;this.rel='stylesheet'");
}
echo $dom->saveHTML();
उपरोक्त आउटपुट:
<link href="style.css" rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link href="style.css" rel="stylesheet"></noscript>
1
Victor
26 पद 2018, 13:32
संबंधित सवाल
नए सवाल
php
PHP एक व्यापक रूप से उपयोग किया जाता है, उच्च-स्तरीय, गतिशील, वस्तु-उन्मुख, और व्याख्या की गई स्क्रिप्टिंग भाषा मुख्य रूप से सर्वर-साइड वेब विकास के लिए डिज़ाइन की गई है। PHP भाषा के बारे में सवालों के लिए इस्तेमाल किया।