Upgrade third party js logic improve load speed.

This commit is contained in:
凡梦星尘
2022-10-26 22:37:03 +08:00
parent 90df1e1247
commit 525c8a7cf5
10 changed files with 58 additions and 27 deletions

View File

@@ -1,12 +1,11 @@
/* global instantsearch, algoliasearch, CONFIG, pjax */
/* Algolia search engine */
NexT.plugins.search.algolia = function() {
document.addEventListener('DOMContentLoaded', () => {
const algoiajs = NexT.utils.getCDNResource(NexT.CONFIG.algolia.js);
const algoliajs = NexT.utils.getCDNResource(NexT.CONFIG.algolia.js);
const instantschjs = NexT.utils.getCDNResource(NexT.CONFIG.algolia.instantjs);
NexT.utils.getScript(algoiajs, {});
NexT.utils.getScript(instantschjs, {}).then(() => {
NexT.utils.getScript(algoliajs);
NexT.utils.getScript(instantschjs, function() {
const { indexname, appid, apikey, hits } = NexT.CONFIG.algolia.cfg;
const indexName = indexname;
@@ -138,7 +137,6 @@ document.addEventListener('DOMContentLoaded', () => {
onPopupClose();
}
});
});;
});
});
}

View File

@@ -1,4 +1,4 @@
/* global CONFIG, pjax, LocalSearch */
/* LocalSearch engine */
class LocalSearch {
constructor({
path = '',
@@ -227,7 +227,7 @@ class LocalSearch {
}
}
document.addEventListener('DOMContentLoaded', () => {
NexT.plugins.search.localsearch = function() {
if (! NexT.CONFIG.localSearch.path) {
// Search DB path
console.warn('`search indexes file` is not configurate!');
@@ -323,4 +323,4 @@ document.addEventListener('DOMContentLoaded', () => {
onPopupClose();
}
});
});
}