
August 27, 2025
Creating a Progressive Web App (PWA) with Angular
Creating a Progressive Web App (PWA) with Angular
In today's digital world, people expect web apps to be quick, reliable, and accessible even when they don't have internet connection. The goal of Progressive Web Apps (PWAs) is to meet these needs. When you use them on the web, they feel like native apps. You can run them offline, put them on your device, and they load quickly. Google's Angular is a strong front-end platform that supports making PWAs right out of the box. Through this article, we will show you how to turn an Angular app into a Power UI app.
What is a Progressive Web App?
Progressive Web Apps (PWAs) are a type of web app that gives users an app-like experience by using the latest web features. PWAs are fully compatible with all systems and devices, like desktop computers and cell phones. These are the main features that a PWA has:
- Responsive: It works on all kinds of devices with wide range of screen sizes.
- Offline support: Supports offline use of saved files to load even when not connected to the internet.
- Installable: Customers can install the app on their home screen and update it.
- Fast and reliable: uses caching and background sync to make things faster and work better.
Setting Up an Angular Project
Do not forget to install Angular CLI before you start. Use the following command to install it:
npm install -g @angular/cli
Now, create a new Angular application:
ng new angular-pwa-demo
cd angular-pwa-demo
To make the project, just leave the settings as they are and wait.
Adding PWA Support in Angular
The @angular/pwa package from Angular makes public support for PWAs. You can use the Angular CLI to add it:
ng add @angular/pwa
With this script, you can add the following files and configurations to your project:
- manifest.webmanifest: This file describes how the app will look and work after it is installed.
- ngsw-config.json: This is the configuration file for the Angular Service Worker.
- Splash screens and icons for various gadgets.
- Changes to angular.json to allow support for service workers.
Understanding the Service Worker and Manifest
A service worker is a tool that works independently of your web page and in the background. It takes care of things like background sync, caching, and push messages. The service worker in Angular automatically stores static files and serves them when the app is not online.
The name, description, theme colours, and icons for your app are all in the Web App Manifest (manifest.webmanifest). Browsers can then show a "Install" button and open the app in a new window.
Example from manifest.webmanifest:
{
"name": "Angular PWA Demo",
"short_name": "PWA Demo",
"theme_color": "#1976d2",
"background_color": "#ffffff",
"display": "standalone",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "assets/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
]
}
Building and Testing the PWA
You need to build the app in production mode so that service workers can use it.:
ng build --prod
The service worker will only be added during production builds. A basic server is what you need to test your app locally:
npm install -g http-server
http-server -p 8080 -c-1 dist/angular-pwa-demo
Get your computer ready and go to http://localhost:8080. When you go offline, you should see a "Install" message and be able to use the app without an internet connection.
Enabling Offline Functionality for Dynamic Content
The service worker in Angular only saves static files by default. You can also cache changeable data in your app, like API replies, by making changes to ngsw-config.json.
Example configuration to cache API data:
{
"dataGroups": [
{
"name": "api-data",
"urls": ["/api/**"],
"cacheConfig": {
"maxSize": 100,
"maxAge": "1d",
"timeout": "10s",
"strategy": "freshness"
}
}
]
}
If the request fails, this tells the service worker to try getting it from the network first and then from the cache.
Deploying Your Angular PWA
You can use services like Firebase Hosting, Vercel, or Netlify to deploy your app online once it is ready. Firebase offers an easy way to do things:
1. Install Firebase CLI:
npm install -g firebase-tools
2. Initialize Firebase in your project:
firebase init
3. Deploy:
firebase deploy
You can now run your PWA on platforms that accept it.
Conclusion
Users have a better experience with Progressive Web Apps because they make web apps easier, installable, and accessible when you are not online. Angular makes it easy to add PWA functions with very little setup. With the Angular CLI and service worker, developers can quickly turn a regular web app into a modern, stable PWA. If you want to make your Angular app easier to use and faster for both mobile and PC users, you should add PWA support.
29 views