From 9d971201978e993a9af337d9cd5396a1ea225f00 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 23 Mar 2023 01:29:17 +0800 Subject: [PATCH] perf(assets): reduce HTTP requests to CDN --- _includes/comments/giscus.html | 72 ++++++++++++++++++--------------- _includes/head.html | 2 - _includes/js-selector.html | 38 +++++++++++------ _includes/jsdelivr-combine.html | 6 --- _includes/mermaid.html | 57 +++++++++++++------------- _includes/mode-toggle.html | 65 +++++++++++++++++++---------- _includes/search-loader.html | 49 +++++++++++----------- _includes/toc.html | 3 -- _layouts/default.html | 14 +++---- 9 files changed, 167 insertions(+), 139 deletions(-) diff --git a/_includes/comments/giscus.html b/_includes/comments/giscus.html index 29b848f..ed918a9 100644 --- a/_includes/comments/giscus.html +++ b/_includes/comments/giscus.html @@ -1,44 +1,54 @@ diff --git a/_includes/head.html b/_includes/head.html index 6407c9c..f767edb 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -108,8 +108,6 @@ - - {% unless site.theme_mode %} {% include mode-toggle.html %} {% endunless %} diff --git a/_includes/js-selector.html b/_includes/js-selector.html index 7d2224c..895ccef 100644 --- a/_includes/js-selector.html +++ b/_includes/js-selector.html @@ -1,27 +1,35 @@ + + +{% assign urls = site.data.assets[origin].jquery.js + | append: ',' + | append: site.data.assets[origin].bootstrap.js + | append: ',' + | append: site.data.assets[origin].search.js +%} + {% if page.layout == 'post' %} {% if site.google_analytics.pv.proxy_endpoint or site.google_analytics.pv.cache_path %} - + {% assign urls = urls | append: ',' | append: site.data.assets[origin].countup.js %} {% endif %} {% endif %} {% if page.layout == 'post' or page.layout == 'page' or page.layout == 'home' %} - {% assign _urls = site.data.assets[origin].lazysizes.js %} + {% assign urls = urls | append: ',' | append: site.data.assets[origin].lazysizes.js %} {% unless page.layout == 'home' %} - {% assign _urls = _urls + + {% assign urls = urls | append: ',' | append: site.data.assets[origin]['magnific-popup'].js | append: ',' | append: site.data.assets[origin].clipboard.js %} {% endunless %} - - {% include jsdelivr-combine.html urls=_urls %} {% endif %} {% if page.layout == 'home' @@ -32,7 +40,9 @@ %} {% assign locale = site.lang | split: '-' | first %} - {% assign _urls = site.data.assets[origin].dayjs.js.common + {% assign urls = urls + | append: ',' + | append: site.data.assets[origin].dayjs.js.common | append: ',' | append: site.data.assets[origin].dayjs.js.locale | replace: ':LOCALE', locale @@ -41,10 +51,18 @@ | append: ',' | append: site.data.assets[origin].dayjs.js.localizedFormat %} - - {% include jsdelivr-combine.html urls=_urls %} {% endif %} +{% if page.content contains ' {% endif %} - - - - {% if jekyll.environment == 'production' %} {% if site.pwa.enabled %} diff --git a/_includes/jsdelivr-combine.html b/_includes/jsdelivr-combine.html index 960eeb1..cffa699 100644 --- a/_includes/jsdelivr-combine.html +++ b/_includes/jsdelivr-combine.html @@ -5,7 +5,6 @@ {% assign domain = 'https://cdn.jsdelivr.net/' %} {% for url in urls %} - {% if url contains domain %} {% assign url_snippet = url | slice: domain.size, url.size %} @@ -16,15 +15,10 @@ {% endif %} {% elsif url contains '//' %} - - {% else %} - - {% endif %} - {% endfor %} {% if combined_urls %} diff --git a/_includes/mermaid.html b/_includes/mermaid.html index 2ec8029..967cfb4 100644 --- a/_includes/mermaid.html +++ b/_includes/mermaid.html @@ -1,59 +1,58 @@ - - - - - diff --git a/_includes/mode-toggle.html b/_includes/mode-toggle.html index ada0061..a347750 100644 --- a/_includes/mode-toggle.html +++ b/_includes/mode-toggle.html @@ -1,14 +1,22 @@ - + - diff --git a/_includes/toc.html b/_includes/toc.html index 6b18693..1eb3dcd 100644 --- a/_includes/toc.html +++ b/_includes/toc.html @@ -10,7 +10,4 @@
{{- site.data.locales[include.lang].panel.toc -}}
- - - {% endif %} diff --git a/_layouts/default.html b/_layouts/default.html index 2349852..755c59e 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -21,7 +21,6 @@ layout: compress {% include sidebar.html lang=lang %} - {% include topbar.html lang=lang %}
@@ -31,14 +30,9 @@ layout: compress {% include search-results.html lang=lang %}
- {% include footer.html lang=lang %} - {% if page.mermaid %} - {% include mermaid.html %} - {% endif %} -
@@ -72,8 +66,12 @@ layout: compress {% endif %} - {% include search-loader.html %} - {% include js-selector.html %} + + {% if page.mermaid %} + {% include mermaid.html %} + {% endif %} + + {% include search-loader.html %}