better-react-mathjax icon indicating copy to clipboard operation
better-react-mathjax copied to clipboard

Load remote script async to boost performance

Open henrymcl opened this issue 1 year ago • 1 comments

By default the script is downloaded at https://cdnjs.cloudflare.com/ajax/libs/mathjax/... without async:

/MathJaxContext/MathJaxContext.js:

function f(t, o) {
    n && (window.MathJax = n);
    var e = document.createElement("script");
    e.type = "text/javascript", e.src = v, e.async = !1, e.addEventListener("load", function () {
      var e = window.MathJax;
      a && a(e), t(e), r && r()
    }), e.addEventListener("error", function (e) { return o(e) }), document.getElementsByTagName("head")[0].appendChild(e)
  }

Is it possible to make it async to boost performance?

henrymcl avatar Oct 17 '24 07:10 henrymcl

Yeah sounds like a reasonable thing to ask for, let me test it for a bit and then make a PR :)

fast-reflexes avatar Oct 17 '24 14:10 fast-reflexes

Just wanted to let you know that I have not forgotten about this but I need to test it a bit so that this doesn't cause any new circumstances for the ability to hide data until typeset. It shouldn't but I want to try it out first. Will probably release a beta which you can try out too and then add it for the next minor release.

fast-reflexes avatar Nov 08 '24 08:11 fast-reflexes

You can try it out now, version 2.0.4-beta1. I will try it out too and make a proper 2.0.4 release once I have confirmed that no hiccups exist :)

Thanks for the suggestion!

fast-reflexes avatar Nov 11 '24 08:11 fast-reflexes

seems great so far

henrymcl avatar Nov 27 '24 05:11 henrymcl

Hi again @henrymcl sorry for the long waiting time for such a simple thing. Present on the MathJaxContext in v. 2.1.0 just released is now the boolean asyncLoad which enables you to run the load of the script in an async fashion. Default is still to not run it async. I'll close this for now, let me know if it doesn't work as expected :)

Thanks for contributing with ideas! 🤝

fast-reflexes avatar Jan 30 '25 21:01 fast-reflexes