Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load KaTeX asynchronously using script async #1064

Closed
aterenin opened this issue Jan 15, 2018 · 6 comments · Fixed by #1580
Closed

Load KaTeX asynchronously using script async #1064

aterenin opened this issue Jan 15, 2018 · 6 comments · Fixed by #1580
Assignees

Comments

@aterenin
Copy link
Collaborator

KaTeX seems to work out of the box with script async. If there are no major drawbacks from using this, I suggest adding it to the README.

@kevinbarabash
Copy link
Member

I can't see why it wouldn't work with script async. The async attribute only affects when the script is loaded, right?

@aterenin
Copy link
Collaborator Author

I believe so. I tested it with the latest alpha version (beta version 404s because it has yet to propagate across the CDN), and it seems to just work. I also tested loading the CSS asynchronously by adding the following to the auto-render code.

var link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-alpha2/katex.min.css";
link.integrity = "sha384-exe4Ak6B0EoJI0ogGxjJ8rn+RN3ftPnEQrGwX59KTCl5ybGzvHGKjhPKk/KC3abb" ;
link.crossorigin="anonymous";
document.getElementsByTagName("head")[0].appendChild(link);

I had to use the load event instead of DOMContentLoaded because it happens later, but other than that, everything seems to just work.

@edemaine
Copy link
Member

Having an async example sounds cool. Calling autorender or whatever upon load event sounds perfect.

@kevinbarabash
Copy link
Member

@aterenin if you have some time, would you mind adding a note in the README.md?

@aterenin
Copy link
Collaborator Author

The code I have above is, for whatever reason, not reliable - have noticed on my own site that it occasionally fails to load the style sheet.

I've thus reverted back to what is in README.md but if I end up figuring out what to change to make it work consistently I'll document everything.

@TruePath
Copy link

TruePath commented Jan 1, 2022

Maybe consider this technique? That's a nice way for those of us who are preprocessing the math on the server to load the css.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants