From 4cd19b8274de7513203738c7a5b6d9d32775cd67 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 9 Nov 2021 01:54:56 +0900 Subject: [PATCH] Close #9450: mathjax: Load MathJax via "defer" strategy To allow configure MathJax via static JS file, it should be loaded via "defer" strategy. --- CHANGES | 1 + sphinx/ext/mathjax.py | 2 +- tests/test_ext_math.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 33d20a45bf5..0c07f48069d 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ Incompatible changes * #9695: The rendering of Javascript domain declarations is implemented with more docutils nodes to allow better CSS styling. It may break existing styling. +* #9450: mathjax: Load MathJax via "defer" strategy Deprecated diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py index 46ca3b33208..eb06908d30e 100644 --- a/sphinx/ext/mathjax.py +++ b/sphinx/ext/mathjax.py @@ -81,7 +81,7 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: Dict domain = cast(MathDomain, app.env.get_domain('math')) if app.registry.html_assets_policy == 'always' or domain.has_equations(pagename): # Enable mathjax only if equations exists - options = {'async': 'async'} + options = {'defer': 'defer'} if app.config.mathjax_options: options.update(app.config.mathjax_options) app.add_js_file(app.config.mathjax_path, **options) # type: ignore diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py index 973fc369943..7c78954b7ff 100644 --- a/tests/test_ext_math.py +++ b/tests/test_ext_math.py @@ -71,7 +71,7 @@ def test_mathjax_options(app, status, warning): app.builder.build_all() content = (app.outdir / 'index.html').read_text() - assert ('' in content)