PWA: Detecting redirects in service workers

PWA app

Why do you need to detect redirects in a PWA page? Well a PWA is established on a specific domain. You might need to redirect to a new domain at some point. You can easily do it server side with simple commands, but as PWA is cached in a specific way it will remain on the old domain. PWA will not be able to do calls to redirected API because of CORS. And it might never move on because when your admin redirected domains you will not be able to get a new service worker either. So you need to think ahead and plan for this. But how?

PWA and HTTP Caching

In my previous PWA article I've covered PWA basics. In this article I will cover more complex situations where a simple Service Worker is not enough. I will also talk about differences between new Service Worker Cache and HTTP Cache and how they interact. That's because they do interact and not knowing how they work together might cause problems.

I assume you have basic knowledge of PWA and you've seen at least a basic Service Worker. If not, please read my previous article first.

From responsive website to PWA in one day

You've probably already heard about Progressive Web Apps, but just to refresh, you are simply building an application from your website. If your application is PWA compatible, users should be able to add a shortcut (link) to the app to their home screen (desktop). The app should also work to some extent off-line, which is done with a help of the Service Worker. Note that by complying with PWA rules you will improve experience for all your users! Not just for mobile users.

In this article I will talk about some basics of transforming an existing website into a PWA. I'm saying those are the basics, but in fact, within a day or two you should be able to create a fully functional PWA. You need to avoid some traps on your way, but I'll try to guide you through this minefield.

Subscribe to PWA