[This post was written by Алексей Нащекин, a developer working on FEE.org]

Web Push API is a new technology that allows web browser to send and receive messages pushed to them from the application server.   Whereas previously, push notifications were only available to apps that were installed on a computer or phone, the web push API supports sending notifications with just a web browser.

With push notifications, a message will be shown to the user even if the web site is opened on another tab of the browser or even if it is not opened at all. Note that it is still experimental technology and each browser (Mozilla, Chrome, Safari, Microsoft Edge) has its own implementation of it. Some browsers (Internet Explorer) do not support it at all. More so, there is currently no standard mechanism of sending and processing the messages, so each browser uses its own way. For example, Firefox will show the user only a limited number of push notifications, but the limit is refreshed on every site visit. Chrome will not have such restriction. There is also some slight differences in the Firefox and Chrome push notifications sending workflow.

The receiving of push notification is achieved by registering some service worker process, which will live in the user’s browser. Each process will have its own unique endpoint on registration. When you will send the push notification, you will send it to that endpoint (https://android.googleapis.com/gcm/send/{some big random key}, for example) and the google API (or Firefox API) will care about transferring this to the user’s browser.

The icon, the header and the site URL parts of the notification could be hardcoded as the constants in the process of service worker registration. However, if you want to send a message, then the message must be encrypted. The encryption algorithm is quite complex. There are currently working realizations on PHP and node.js, but FEE.org uses Umbraco and .NET, and there is no working solution for it yet.

Therefore, I needed to either convert working node.js solution to C# (which I am planning to do sometime) or find a workaround for it. Due to FEE.org business logic process, I found a more elegant and quick solution. There are not many articles published on FEE.org per hour, so I can implement an API with the latest published article data and then make service worker to ask it for that data on each push notification received.

If you want to implement Web Push Notifications on your site – there is a very good article from Mozzila and a demo project on GitHub.

In my opinion, this technology is still in a raw state, but I hope it soon will grow into a more clear and customizable solution. However, even now it provides a valuable way of informing user of your web application news.