Unloading KaTeX scripts from pages where not in use
-
Hi,
We’re running into an issue unloading KaTeX scripts from pages where we are not using the shortcode. We’ve tried the “Load KaTeX assets conditionally”, but then it does not load the assets when we need them.
Assets loaded conditionally enabled: https://share.getcloudapp.com/Z4uGgJn9Assets loaded conditionally disabled:
https://share.getcloudapp.com/04uvB0vmWe’ve also tried using Perfmatters to unload KaTeX from the pages where it’s not in use, but there’s still one script loading from somewhere on every page:
function _katexRender(rootElement) { const eles = rootElement.querySelectorAll(“.katex-eq:not(.katex-rendered)”); for(let idx=0; idx < eles.length; idx++) { const ele = eles[idx]; ele.classList.add(“katex-rendered”); try { katex.render( ele.textContent, ele, { displayMode: ele.getAttribute(“data-katex-display”) === ‘true’, throwOnError: false } ); } catch(n) { ele.style.color=”red”; ele.textContent = n.message; } } } function katexRender() { _katexRender(document); } document.addEventListener(“DOMContentLoaded”, function() { katexRender(); // Perform a KaTeX rendering step when the DOM is mutated. const katexObserver = new MutationObserver(function(mutations) { [].forEach.call(mutations, function(mutation) { if (mutation.target && mutation.target instanceof Element) { _katexRender(mutation.target); } }); }); const katexObservationConfig = { subtree: true, childList: true, attributes: true, characterData: true }; katexObserver.observe(document.body, katexObservationConfig); });
Any tips for either correcting the load assets conditionally option or removing the script above from the pages where the KaTeX shortcode is not in use? Thank you!
The page I need help with: [log in to see the link]
- The topic ‘Unloading KaTeX scripts from pages where not in use’ is closed to new replies.