Make the google translate script lazy load.

This commit is contained in:
凡梦星尘
2022-10-23 18:36:10 +08:00
parent dacf4cd2c7
commit aaa3a1449f
6 changed files with 35 additions and 187 deletions

View File

@@ -8,8 +8,15 @@
{{ partialCached "_thirdparty/others/mermaid.html" . }}
{{ end }}
{{ if .Site.Params.footer.translate }}
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
const element = '#gtranslate';
if (!NexT.utils.checkDOMExist(element)) return;
NexT.utils.lazyLoadComponent(element).then(() => {
window.translateelement_styles='/css/google-translate.min.css';
NexT.utils.getScript('/js/third-party/google-translate.min.js');
});
});
</script>
{{ end }}