Have a service worker, which runs separately from the website/app and can handle notifications sent by the server (known as 'push' notifications, such as you get with regular apps when Facebook wants to sell you something) and also allow the app to work offline