Search code examples
cdnmathjax

Which MathJax CDN script should be used?


I would like to use MathJax within my website, and I have opted to use a CDN method. MathJax.org states that you can put

<script 
   src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'>
</script>

within the HTML <head></head> tags and provided a pre-populated example on jsbin

However, I have noticed when using MathJax within WordPress, the MathJax documentation suggests using

<script type="text/javascript"
   src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

I have noticed, that the difference is in the main part of the src address where the CDN used is cdn.mathjax.org instead of cdnjs.cloudflare.com, and the address points to mathjax/latest/MathJax.js instead of mathjax/2.7.2/MathJax.js.

I have put the second script into the jsbin example to see if there is a difference in function, and the example still works. Is it preferable (or more correct) to use the second script over the first one whether using WordPress or not, with the understanding that the second one will point to the most up-to-date version of MathJax?


Solution

  • As @Bob__ pointed out, and I had just read prior to then, MathJax was shutting down its CDN and they actually

    retired cdn.mathjax.org in April, 2017.
    (Source: docs.mathjax.org)

    The same webpage states that there are many free CDN providers that provide copies of MathJax. Some provide “rolling releases”, i.e., links that update to the latest available version upon release, and cdnjs.com is recommended. This matches Mathjax.org's page at https://www.mathjax.org/cdn-shutting-down/

    They say

    To jump start using cdnjs, you accomplish the first step by putting

    <script type="text/javascript" async
      src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
    </script>
    

    into the <head> block of your document

    Note: the configuration file TeX-MML-AM_CHTML is a great way test all input options at once. You can find leaner combined configuration packages in MathJax documentation.

    Interestingly, before seeing that, carrying out a MathJax libraries search on cdnjs.com provides an updated script tag of

    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js">
    </script>
    

    So the answer is to check for the latest library script tag in cdnjs.com, which is currently for version 2.7.3 and use that one. Currently

    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js">
    </script>
    

    and if you wish to use the TeX-MML-AM_CHTML configuration file, use:

    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-MML-AM_CHTML">
    </script>