使用KaTeX时,为什么在<script>前面放一个<script>,在body后面放一个?
When using KaTeX, why put one <script> in the head and one after the body?
参见this example of the use of KaTeX on a Jekyll website。
- 为什么KaTeX脚本在头部,而在body之后进行KaTeX渲染的内联脚本?
- 如果我在我的 Github 页面网站上使用 KaTeX,是否最好将两个脚本都放在带有
async
或 defer
属性的头部,如 [=15] 中所述=]?
正如您已经提到的:placing script
1) 在 header 中放置一个脚本标记意味着 stop everything before this script is loaded
因此,在您的 KaTeX example 中,为了使示例有效,作者想强调 katex.min
文件应该首先加载和解析,在那之前,他不想 load/parse 任何 html
内容,因为 body 中的第二个 <script>
将失败如果 katex.min
未正确加载。
这只是其中一种方法。但是还有很多像:
Remove the <script>
tag from head and place before the <script>
in body
Remove the <script>
tag after the body and place it after the <script>
tag in head with defer
attribute in both the scripts (so, we need not wait for them to be downloaded and go to body part to print things, and once they are loaded execute them) defer will make sure that everything in the dom
is loaded asynchronously except that the scripts will be loaded in the order which they are declared.
参见this example of the use of KaTeX on a Jekyll website。
- 为什么KaTeX脚本在头部,而在body之后进行KaTeX渲染的内联脚本?
- 如果我在我的 Github 页面网站上使用 KaTeX,是否最好将两个脚本都放在带有
async
或defer
属性的头部,如 [=15] 中所述=]?
正如您已经提到的:placing script
1) 在 header 中放置一个脚本标记意味着 stop everything before this script is loaded
因此,在您的 KaTeX example 中,为了使示例有效,作者想强调 katex.min
文件应该首先加载和解析,在那之前,他不想 load/parse 任何 html
内容,因为 body 中的第二个 <script>
将失败如果 katex.min
未正确加载。
这只是其中一种方法。但是还有很多像:
Remove the
<script>
tag from head and place before the<script>
in bodyRemove the
<script>
tag after the body and place it after the<script>
tag in head withdefer
attribute in both the scripts (so, we need not wait for them to be downloaded and go to body part to print things, and once they are loaded execute them) defer will make sure that everything in thedom
is loaded asynchronously except that the scripts will be loaded in the order which they are declared.