In this part of the code:
|
const HLJSURL = "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.6.0/build/highlight.min.js"; |
|
const HLJSNumURL = "https://cdn.jsdelivr.net/npm/highlightjs-line-numbers.js@2.8.0/dist/highlightjs-line-numbers.min.js"; |
|
const loadHLJS = typeof hljs != "undefined" && typeof hljs.highlightElement != "undefined" ? Promise.resolve() : loadScript(HLJSURL); |
We check if the global variable hljs is present. If not, we load the script. But it seems that if we load multiple code snippets fast enough, hljs will be undefined while they are being loaded, causing multiple <script> tags to appear to load highlightjs.
It can be seen on my website:
This issue may or may not appear depending on the internet connectivity. But it is there. To mitigate this issue, I suggest that we check the existence of the script tag loading highlighjs library instead of checking hljs variable.
In this part of the code:
emgithub/embed-v2.js
Lines 340 to 342 in 684c444
We check if the global variable
hljsis present. If not, we load the script. But it seems that if we load multiple code snippets fast enough,hljswill beundefinedwhile they are being loaded, causing multiple<script>tags to appear to load highlightjs.It can be seen on my website:
This issue may or may not appear depending on the internet connectivity. But it is there. To mitigate this issue, I suggest that we check the existence of the
scripttag loading highlighjs library instead of checkinghljsvariable.