openvibers/openvibe.live Commits

Live: notification-ui.js only when someone needs it (29 KB off signed-out views) (#681)

OP OpenVibers committed 6 days ago · fb9e96cf05 · 2 files, +5 −2

Changes

ddiff --git a/public/index.html b/public/index.html
iindex 5902c0cb..b92567ef 100644
---- a/public/index.html
++++ b/public/index.html
@@@ -506,7 +506,8 @@
<!-- ── OpenVibe shared libs (notifications, account sync, themes) ── -->
<script src="/shared/theme-loader.js" defer></script>
<script defer src="/js/ov-display-menu.js"></script>
--<script src="/shared/notification-ui.js" defer></script>
++<!-- notification-ui.js is not on every page (11-07: 29 KB a signed-out visitor never used): the navbar loads it, by its
++ content hash, when it mounts a signed-in person's bell, and the live-alerts offer loads it when asked. -->
<!-- The requested route's scripts (public/features.json), added by the server after the core ones.
Other routes load theirs on navigation through js/ov-loader.js. -->
<!--ov:route-js-->
ddiff --git a/public/js/app-channel.js b/public/js/app-channel.js
iindex 3ccc866a..7be10c5f 100644
---- a/public/js/app-channel.js
++++ b/public/js/app-channel.js
@@@ -3773,7 +3773,9 @@ async function toggleChannelFollow(username) {
*/
const LIVE_ALERTS_DECLINED_KEY = 'ov_live_alerts_declined_at';
async function offerLiveAlerts(name) {
-- const n = window.OpenVibeNotifications;
++ let n = window.OpenVibeNotifications;
++ // Not on every page any more (index.html): load it the moment it is wanted, if the bar has not yet.
++ if (!n && window.ov && typeof ov.loadScript === 'function') { try { await ov.loadScript('/shared/notification-ui.js'); } catch { /* */ } n = window.OpenVibeNotifications; }
const box = document.getElementById('toast-container');
if (!box || !n || typeof n.pushStatus !== 'function' || typeof n.enablePush !== 'function') return;
if (document.getElementById('live-alerts-offer')) return;