3

I need to Defer merged css using JavaScript. Is there any possibilities to defer merged css. Example code i want to do.

    <noscript id="deferred-styles">
      <link rel="stylesheet" type="text/css" href="https://xxxx.xx/static/version1xxxx/_cache/merged/f64d21109ccdd1dc8924b35f2614e40f.min.css"/>
    </noscript>

<script>
  var loadDeferredStyles = function() {
    var addStylesNode = document.getElementById("deferred-styles");
    var replacement = document.createElement("div");
    replacement.innerHTML = addStylesNode.textContent;
    document.body.appendChild(replacement)
    addStylesNode.parentElement.removeChild(addStylesNode);
  };
  var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
      window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  if (raf) raf(function() { window.setTimeout(loadDeferredStyles, 0); });
  else window.addEventListener('load', loadDeferredStyles);
</script>
1
  • Is there no one can do this? – Jagveer Singh Oct 13 '20 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.