After deploying the blog online, I found that the Katex formulas would not display properly, while the same Html file displayed correctly in the local environment.
The core parsing code is as follows:
| |
By adding logging, I found that the DOMContentLoaded event was not firing.
But I couldn’t figure out the reason for a long time, until I noticed that in the online version the <script> tag had become something like <script type="d6a94c0af8a975daac5bee56-text/javascript">.
Eventually I recalled that Cloudflare had Rocket Loader enabled.
Rocket Loaderis aCloudflarefeature that loadsJavaScriptasynchronously to improve page load speed.
However, Rocket Loader may change the loading order and thereby cause some JavaScript code to fail to execute properly.
I disabled Rocket Loader for now, and the problem was solved.
You can also disable Rocket Loader by adding data-cfasync="false" to the tag, but since that would require modifying the Theme, I won’t make that change for now.