From 7ba559a8a93bacfba4c0af17d20437f8c29ebd62 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 5 Aug 2024 13:55:07 -0700 Subject: [PATCH] base.html: Drop dependency on modernizr.js library - The library performs a large number of tests to determine if various features are available in the browser. In Debian most tests seem to be present unlike other methods of distribution where users select which tests they want and build a customized library for their app. This leads to increased page load time. - The only functionality we use from Modernizr library are the .js and .no-js classes we use in our CSS styling. Modernizr is not needed by Bootstrap library. We don't use 'Modernizr.' properties in Javascript. - A bug in the test to determine if an element with type="number" allows localization or not causes the page to scroll down to the end. This behavior appeared in version 3.x of modernizr and despite the bug report and the fix, it is not gone. Dropping modernizr fixes this issue. Tests: - The logout link in the header bar is visible only when Javascript is disabled. - The dropdown icons next to header menus only appear when Javascript is enabled. - For each feature detection provided by Modernizr library, search if our project is using that in CSS styling. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- debian/control | 1 - plinth/templates/base.html | 4 +--- static/jslicense.html | 7 ------- static/themes/default/js/main.js | 11 +++++++++++ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/debian/control b/debian/control index 6801a41a5..f05ca8b2f 100644 --- a/debian/control +++ b/debian/control @@ -101,7 +101,6 @@ Depends: libglib2.0-bin, libjs-bootstrap4, libjs-jquery, - libjs-modernizr, lsof, netcat-openbsd, network-manager, diff --git a/plinth/templates/base.html b/plinth/templates/base.html index e86199692..3bc8e83a5 100644 --- a/plinth/templates/base.html +++ b/plinth/templates/base.html @@ -7,7 +7,7 @@ {% endcomment %} - + @@ -54,8 +54,6 @@ - - diff --git a/static/jslicense.html b/static/jslicense.html index 22a9808fc..00ffac34e 100644 --- a/static/jslicense.html +++ b/static/jslicense.html @@ -25,13 +25,6 @@ twitter-bootstap3 - - - modernizr.min.js - Expat - - modernizr - jsxc-plinth.js diff --git a/static/themes/default/js/main.js b/static/themes/default/js/main.js index 412ad493a..eaeb86b03 100644 --- a/static/themes/default/js/main.js +++ b/static/themes/default/js/main.js @@ -22,6 +22,17 @@ for the JavaScript code in this page. */ +/* + * Remove the 'no-js' class from the element. CSS utilizing this can + * create different rules when Javascript is available and when it is not. This + * functionality was provided by the Modernizr library earlier. + */ +document.addEventListener('DOMContentLoaded', function(event) { + const html = document.querySelector('html'); + html.classList.remove('no-js'); + html.classList.add('js'); +}); + /* * Refresh page if marked for refresh. */