Include MathJax only if there are formulas on the page
See original GitHub issue- I’ve read the contribution guidelines and agree with them
I want to suggest an idea and checked that …
- … to my best knowledge, my idea wouldn’t break something for other users
- … the documentation does not mention anything about my idea
- … there are no open or closed issues that are related to my idea
Description
MkDocs includes tex-mml-chtml.js
into every page which is an additional ~752Kb transfer.
Serving the MathJax-specific JS only if rendered page contains $...$
blocks will save close to the megabyte per page.
Use Cases
Any case where serving additional traffic is undesirable. Which is… Every case?
Screenshots / Mockups
N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
MathJax Frequently Asked Questions
MathJax loads components only when needed so there is a big difference between what is loaded on a page without mathematics and one...
Read more >MathJax Frequently Asked Questions
Will MathJax make my page load slower even if there's no math?¶. It depends on how you have configured and loaded MathJax. The...
Read more >Loading and Configuring MathJax
It is best to load MathJax in the document's <head> block, but it is also possible to load MathJax into the <body> section,...
Read more >Modifying Math on the Page — MathJax 1.0 documentation
To do that, you need to use the MathJax.Hub.Typeset() method. This will cause the preprocessors (if any were loaded) to run over the...
Read more >What is MathJax? — MathJax 3.2 documentation
MathJax allows page authors to write formulas using TeX and LaTeX notation, MathML (a World Wide Web Consortium standard for representing mathematics in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@facelessuser , Works like a charm, thank you!
@squidfunk ,
Solution from Isaac works well, however having this happening automatically is easier / less confusing for an end-user. Depends on the complexity of implementation I reckon; certainly your call.
Ah, the problem is that you are including it in
extra_javascript
, which will include it on every page. I actually include it at the end of the page that I want to have MathJax. I do this via the Snippets extension: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/.I point Snippets to my
_snippets
folder: https://github.com/facelessuser/pymdown-extensions/blob/master/mkdocs.yml#L131And then I place this at the bottom of the page I want to use MathJax:
You can see that
mathjax.txt
contains my config and the MathJax lib: https://github.com/facelessuser/pymdown-extensions/blob/master/docs/src/markdown/_snippets/mathjax.txt