HomeHow to
JavaScript

How to send push notifications with JavaScript

Enhance your JavaScript app with push notifications. In this article, we'll cover the steps to integrate the Web Push API into your JavaScript project and send push notifications to your users.

How to send push notifications with JavaScript Logo
Large cover image for How to send push notifications with JavaScript

Step 1: Set up your JavaScript project

Progressier can enhance your JavaScript web app with additional features such as push notifications and the ability to be installed as a Progressive Web App (PWA). You can incorporate Progressier into your project when your app is live and accessible at a custom domain.

Step 2: Create a Progressier account

Progressier is a web toolkit that allows you to easily add new capabilities to your JavaScript app (and apps from hosting providers as well) using little to no code at all.

If you haven’t done so already, create your Progressier account. It comes with a free trial (no credit card required!) so you can test all features free of charge for 14 days without risk.

Step 3: Turn your JavaScript project into a PWA

Next, create your JavaScript app in Progressier. Go to New PWA, then select JavaScript in the first dropdown menu. Give your app a name and paste the URL of your JavaScript project in the third field.

Step 4: Complete your onboarding

Complete the tasks shown on the screen to finish making your JavaScript app universally installable and augment it with push notifications. It even comes with a complete solution for designing app screenshots and gathering reviews.

Step 5: Allow push notifications on your domain

Click on the in the URL bar to open permissions. If you followed instructions correctly, notifications should be authorized on your domain.

Step 6: Send your first push notification

Our Push Composer allows you to compose a notification, select a specific group of users of your JavaScript app to send it to, and even schedule its actual delivery from 15 minutes to 14 days in the future.

Step 7: Connect your user data (optional)

Sending the same notification to every user for marketing purposes is one thing. Sending notifications programmatically to a user to react to events in your JavaScript app is another. Luckily, Progressier comes with a solution for both use cases. Simply connect your user data (e.g. a user ID or user email), then call our Push API in your server-side code to send a push notification to a specific user. You don't have to manage push subscriptions on your end.

Why add push notifications to your app?

1. Improving user engagement: Push notifications can help keep users engaged with your app by delivering timely and relevant updates and information.

2. Driving traffic to the app: Push notifications can help drive traffic back to your JavaScript app by providing users with a reason to open it.

3. Increasing retention rates: Push notifications can help keep users coming back to the app by providing them with valuable and interesting content.

4. Boosting conversion rates: By delivering personalized and targeted messages to users, push notifications can help increase conversion rates and drive sales.

5. Providing a better user experience: Push notifications can provide a more convenient way for users to receive updates and information from your app, improving the overall user experience.

The disadvantages of push notifications in JavaScript

Some users may consider push notifications to be obtrusive, especially if they're not personalized and used as a marketing tool. Make sure to use them sparingly.

What are the best push services for JavaScript apps?

There are many different push notification service providers to choose from for your JavaScript app, and the best one for you will depend on your specific needs and requirements. Some of the most popular push notification service providers include:

- Firebase Cloud Messaging: a cross-platform messaging solution that lets you reliably deliver messages at no cost. You can use FCM to send messages to clients on iOS, Android, and the web, as well as on desktop applications.

- OneSignal: This is a cross-platform messaging service that supports Android, iOS, and web platforms. It offers a range of features, including segmentation, A/B testing, and support for multiple languages.

- Progressier: probably the best option if you develop web apps as it also comes with additional functionality designed to enhance web apps specifically, e.g. targeted push notifications.

- Amazon Simple Notification Service (SNS): This is a flexible, cross-platform messaging service provided by Amazon that supports a wide range of platforms, including Android, iOS, and the web. It offers features such as topic-based subscriptions and message filtering.

Creating your own push service

Creating your own push solution is feasible, but requires some non-trivial engineering. Chances are you'll be better off using an established push service provider. But if you still want to do this yourself, here are the four components you'll need:

1. Widgets to allow push notifications: you can directly call the native push interface. But if users block notifications right here and there, you won't be able to ask them again. Or you can display a widget that tells users why they should allow notifications before actually calling the native browser interface. This is the recommended way to do this.

2. A push subscription database: once a user has allowed push notifications, you'll be given a specific API endpoint for each user. Save it into your database so you can message users later.

3. An interface for preparing the payload of the notification: a push notification is a JSON object with properties such as title, body, and icon which define the content of the notification itself. You must have a user interface that allows you to define these parameters before they're sent to your push queue.

4. A delivery service: if you have more than a few hundred simultaneous recipients, you'll need to build a push queue that takes care of processing push notifications.

Which devices and web browsers can receive push notifications?

- Windows/Chrome
- Windows/Edge
- Windows/Firefox
- Windows/Opera
- macOS/Firefox
- macOS/Chrome
- macOS/Edge
- macOS/Opera
- Android/Chrome
- Android/Samsung Internet
- macOS/Safari
- iOS/Safari

Your app here

Augment your JavaScript app with push notifications

Elevate your app with our no-code push notification toolkit

Generate PWA See plans