Capturing MathJax output as static content instead of running MathJax every visit

481 views
Skip to first unread message

songof...@gmail.com

unread,
Oct 22, 2014, 9:41:41 AM10/22/14
to mathja...@googlegroups.com
Hi all – I'm a MathJax novice and want to render beautiful equations on my site. One thing is puzzling me. As I understand it, MJ is a JavaScript program that is invoked in the page source every time a visitor loads a page. The browser is reaching out to a MJ server if CDN is setup, or running the JavaScript hosted on my own server, right? So why wouldn't we just take the output for a given page/equation – the HTML/CSS output or the SVG – and store it in the page source? Why would we have MathJax run every time when we can store the output code? Wouldn't a page load much faster if the HTML/CSS output was already there instead of having to run a JavaScript program with every visit to regenerate it? What am I missing?

Peter Krautzberger

unread,
Oct 22, 2014, 10:07:22 AM10/22/14
to mathja...@googlegroups.com
Hi,

The main reasons are

* The HTML-CSS output is highly browser and client dependent. From basic things like installed fonts to tricky things like hacks around browser and OS bugs, MathJax does a lot of work to guarantee identical display across all browsers. So in a very real sense, you cannot store the HTML-CSS output -- as soon as it gets somewhat complex, it will not render well across browsers.
* Responding to the client. The basic example is MathJax's line-breaking algorithm; without the context of a client you cannot provide very good linebreaking. Similarly, MathJax matches the ex height of the surrounding font (which will very likely depend on the client); without this matching the results can look rather poor. Finally, a user might use client-side extensions (e.g., stylesheets for readability) in which case pre-rendered content will easily break.
* Accessibility. MathJax uses MathML internally and can expose this to screenreaders such as MathPlayer and ChromeVox, including advanced features such as navigation and synchronized highlighting. Whenever you render mathematics into static output that is not MathML, you'll be doing the serious damage to your content.

Still, there are scenarios where pre-rendering is a necessity, e.g., JS/MathML disabled environments such as feed readers and ebook reading systems. Similarly, you can use pre-rendering as a preview mechanism for MathJax to enhance the user experience (MathJax can replace images on the fly to provide progressive enhancement). For this, you can leverage MathJax's SVG output (and the upcoming CommonHTML output) which is browser-independent. Check out MathJax-node which was build for such situations.

Regards,
Peter.



On Wed, Oct 22, 2014 at 3:41 PM, <songof...@gmail.com> wrote:
Hi all – I'm a MathJax novice and want to render beautiful equations on my site. One thing is puzzling me. As I understand it, MJ is a JavaScript program that is invoked in the page source every time a visitor loads a page. The browser is reaching out to a MJ server if CDN is setup, or running the JavaScript hosted on my own server, right? So why wouldn't we just take the output for a given page/equation – the HTML/CSS output or the SVG – and store it in the page source? Why would we have MathJax run every time when we can store the output code? Wouldn't a page load much faster if the HTML/CSS output was already there instead of having to run a JavaScript program with every visit to regenerate it? What am I missing?

--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

songof...@gmail.com

unread,
Nov 2, 2014, 12:16:42 AM11/2/14
to mathja...@googlegroups.com
Thanks for the explanation Peter. This helps a lot.

Joe
Reply all
Reply to author
Forward
0 new messages