diff --git a/aleksis/core/static/js/main.js b/aleksis/core/static/js/main.js index 615f8b287df18ed38c57d1f44358073bb74bcf61..18a73bd9674a777704bb07164d52507b74666b34 100644 --- a/aleksis/core/static/js/main.js +++ b/aleksis/core/static/js/main.js @@ -110,3 +110,11 @@ $(document).ready(function () { el.addClass("closed").removeClass("opened"); }); }); + +// Show notice if serviceworker broadcasts that the current page comes from its cache +const channel = new BroadcastChannel("cache-or-not"); +channel.addEventListener("message", event => { + if (event.data) { + $("#cache-alert").removeClass("hide") + } +}); diff --git a/aleksis/core/static/js/serviceworker.js b/aleksis/core/static/js/serviceworker.js index 818e27cb7d28e820431a4ac28ba6fdf0c422deb7..e553301d268efd0ffeedece96c4dc674b42606ce 100644 --- a/aleksis/core/static/js/serviceworker.js +++ b/aleksis/core/static/js/serviceworker.js @@ -59,7 +59,8 @@ function fromCache(event) { // Use the precached offline page as fallback return caches.match(offlineFallbackPage) } - + const channel = new BroadcastChannel('cache-or-not'); + channel.postMessage(true); return matching; }); }); diff --git a/aleksis/core/templates/core/base.html b/aleksis/core/templates/core/base.html index 2087829da24c157b7dc0a797da776d7bb1cc9a3b..79608b185084cdef86774254500288537ec52ec2 100644 --- a/aleksis/core/templates/core/base.html +++ b/aleksis/core/templates/core/base.html @@ -109,6 +109,12 @@ {% endfor %} {% endif %} + <div id="cache-alert" class="alert info hide"> + <p> + <i class="material-icons left">info</i>{% trans "This page may contain outdated information since there is no internet connection." %} + </p> + </div> + {% block no_page_title %} <h4>{% block page_title %}{% endblock %}</h4> {% endblock %} @@ -174,5 +180,6 @@ {% include_js "jquery-sortablejs" %} <script type="text/javascript" src="{% static 'js/search.js' %}"></script> <script type="text/javascript" src="{% static 'js/main.js' %}"></script> + </body> </html>