From e3c391f13fa009aba309b241d1c7c6fe6153c823 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 11 Dec 2020 05:39:46 +0000 Subject: [PATCH] Search: Lazy load search JS on first interaction (or after 5s) This will reduce the QUnit homepage total uncompressed size by ~70 KB from 360KB to 290KB. --- _includes/search.html | 50 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/_includes/search.html b/_includes/search.html index be5af99..d375b7e 100644 --- a/_includes/search.html +++ b/_includes/search.html @@ -12,13 +12,38 @@ * https://www.jsdelivr.com/package/npm/algoliasearch * https://www.jsdelivr.com/package/npm/autocomplete.js -Remember to use the 'defer' attribute. +We use type="module" as a natural way to cut the mustard, +executing the script only on modern browsers with ES6 support, +and causing no errors on older browsers. +See https://responsivenews.co.uk/post/18948466399/cutting-the-mustard {% endcomment %} - -