Home / Tech / How to turn a website into a PWA

How to turn a website into a PWA

We need to understand what is a progressive web app – PWA before we turn our website into one. According to the internet, a PWA is like a clone child of web and mobile applications. However odd that sounds, it’s probably the easiest way to explain what exactly progressive web apps are. But is the internet right? 


There is no other better way to find out the definition of a PWA than to “hear from the horse’s own mouth”. So today, we will first head to the Google developer platform for a bonafide definition of what is a PWA. Then, we embark on the journey that is the essence of this article – how to turn a website into a PWA.


What is a PWA?

According to developers.Google.com “a PWA is not an API or a technology, but it is a web development approach that uses a combination of tools and technologies already available to create targeted ideal user experiences. It shows how to use service workers, APIs, and an application shell architecture for meaningful offline experiences, fast first load, and easy user reengagement upon repeat visits.”


Okay, people, Google developers’ definition is comprehensive but also quite a mouthful. What they – who is an authority on this topic – are simply saying, is that a PWA is a set of functionality. When implemented on a web app, this functionality makes it work more like a native mobile app.


What is a native app?

Loosely defined, a native app is a mobile application that uses the same programming tools like our mobile devices. For example, a native iOS app will use Swift, while a native Android app will use Java. Therefore, users download these apps from the Apple store, Google Play Store, or other respective platforms out there and install them on their mobile devices.

what is a native app
Source: w2ssolutions.com

The reason why native apps are so popular is that platform-specific users – iOS users, Android users, etc. – are familiar with the native feel they provide. Or, simply put, each type of user knows and loves the UI/UX of their respective platforms. So, naturally, they will prefer an application that brings those elements with it. 


PWAs vs. native apps

So, progressive web apps are a set of functions on top of a “traditional” web application, that turns it into a mobile app. But, PWAs are more than just that. They also bring those native elements that users love and look for in an app. And thus, PWAs turn simple websites into an almost naive app. 


Some of the native features that can be added to an existing web application to transform it into a PWA are offline accessibility, push notifications, icon installed on the home screen, background sync, media API, and also geolocation API.


As Google developers state, PWAs are “user experiences that have the reach of the web” and therefore characterized by three major qualities – they are reliable, fast, and engaging.


How PWAs are more beneficial than native apps

Some native apps for services like traveling for example take more storage space and are sometimes sluggish. So, they are not worth installing on a phone. Or, best-case scenario, users download the app, use it once to book a flight or accommodation just because of the offers. Then once they come back from vacation, they uninstall it to save storage.


PWAs on the other hand take much less space. Moreover, as discussed earlier, they are quicker to launch into the browser for users who are now impatient with slow websites. Not to mention that, like native apps, PWAs also come with offline support, push notifications, and more.


However, this is only one example of how PWAs are better than a native app. Another benefit is development time and costs. Native apps, because they use the same technology as the device itself, need one version of the code base for each device. It’s basically building a new app for iOS, Android, and so on. The more platforms, the more developers, the longer the time, and the higher the cost.


PWAs are basically websites, therefore they are built once and work on any platform. One app, that’s it. And they live in the browsers, so no hassle with pushing the app on every app store out there. Fast, affordable, and convenient.


Who can turn their site into a PWA?

Anyone can turn their website into a PWA. From individuals like bloggers and influencers who want their users to easily access their sites, to small, medium, and large businesses. With great features like geolocation, customers see nearby stores or driving directions. 


There is also the media API that accesses a device’s native cameras which can be immensely helpful, quick, and cheap for instance in identifying oneself for certain services like registering on Airbnb or at the notary for certain legal services.


Advantages of a PWA in summary

PWA offers a myriad of benefits that make one’s application enjoyable for targeted users. And, as Google developers put it in their definition, they are an ideal way for “easy user re-engagement upon repeated visits.”


Basically, the benefits of a PWA are that they support push messages, show notifications, they look good on any device. They also work without an App store, they access native device features like camera and work offline.


Core building blocks/features for PWA

There are four primary building blocks for PWAs – the service workers, the application manifest, the background synchronization, and the web push.



The service workers are Javascript code supported by the browser, that is running in the background process even if the application is closed. So, on top of other features that service workers provide, they are also the ones responsible for a PWA working offline. This process is possible by caching and serving data without an internet connection.


The application manifest is what makes the web application installable on home screens. At the same time, background synchronization sends requests once the internet connection is restored. Finally, the web push is the push or server notifications that run in the background, independent from any opened tabs.


What type of websites can be turned into PWA?

Something happening progressively usually means gradual development – in stages over time. In the case of web apps, progressive means that no matter the type of web application, it can be converted into a PWA. 


We know what you’re thinking. “What if I have a legacy web app and it is using an older technology. Surely I have to re-write code to convert it to a PWA”. Far from it. All you need to do is select the features you want and add them on top of your legacy system. For instance, add a service worker and an application manifest for now. Later on, you can add a push notification and whatever else you want.


The same applies to modern web apps. You can convert them into PWAs gradually, by adding the essential features like app manifest, service worker, advanced caching, and then stop. Later on, add a geolocation API or any other feature until fully converted to PWA. However, if you are only now building the website and are already thinking about converting it, it’s best you do it in full from the beginning. 


How to turn website into a pwa at wiredelta.com

Now after going through most of the concepts to do with PWA including and not limited to; what are PWAs, should normal people convert their web app into PWA and is it beneficial to them, how to identify PWAs-their features, the core building features of PWA, whether PWA and SPA are one and the same – differences emerge and what the word progressive means in PWAs. It is time to move to turning/converting our website into a PWA.


How to turn a website into a PWA 

Finally, we saved the best for last, now we can turn our website into a PWA. But, first you need to be familiar with JavaScript – beginner to intermediate level – HTML and CSS. If you are also comfortable with service workers, that’s great but not mandatory.


Then, you will need a text editor like Visual Studio Code, Sublime, Brackets, Notepad++ or any IDE of your choice learn how to turn a website into a PWA. Make sure you use a browser that supports service workers like Google Chrome. And finally, you need to generate an app manifest. And, of course, aside from service workers and the app manifest, you will also need a web app to turn into PWA. Ready? Let’s get started!


Step 1 – Prepare a website to convert

In this guide, we will show you step-by-step how to turn a regular website into a PWA. So let’s start by creating a simple, basic website that we will convert as seen below. 


Turning a simple website into a progressive web app

We will start by opening our coding editor – we are using Visual Studio IDE, but you can use whichever editor you fancy. First, create all the folders needed for a basic web app. These include the images folder, index.html file, manifest.json, and the service workers file as sw.js. The folders should look something like in the print screen below.


Difference between progressive web apps and websites


Next, open the index.html file created and populate it with the code presented below. Don’t worry, there’s not a lot of HTML code to write. Copy all the code as it appears in the screenshot below.


how to turn a website into a pwa


Step 2 – Service workers

Open your service worker file-sw.js and input your code as it appears in the screenshot below. If you have CSS, app.js files and any other files for running your website, add them at line six in the code below, where the index.html is.


how to turn a website into a pwa


Step 3 – App manifest

Next, create your application manifest by opening the manifest.json file you already made in the beginning. Now fill the manifest.json file with the code below.


how to turn a website into a pwa app manifest


Add your icons into the image folder if they are not already there as below. Please remember that the icons should be in eight different sizes ranging from 72×72 to 512×512 to cater to various devices. Note that the icon sizes shown above are just an example.


how to turn a website into a pwa image folder


After creating the manifest.json file, connect it to your web application in order to access and add the home screen functionality and icon installation. We make the connection by adding the following code in the head of the index.html.


How to turn a website into a pwa manifest json


When you are done writing the above piece of code in the head of the index.html, file your whole index.html file should resemble the screenshot below.


how to turn a website into a pwamanifestfile


Next, we will have to place a script in the head tag just after the manifest link, but before we close the head tag because the PWA needs it when the page loads, and for caching files. Below is the piece of code for the script.


How to turn a website into a pwa scripts wiredelta.com


When you finish writing the script code, your index.html file should look like in the screenshot below.


What websites can become PWA


Congratulations, you have now learned how to turn a website into a PWA. To confirm, open your application in a web browser that supports service workers like Chrome. Your new PWA should look something like the screenshot below.


how a PWA looks like

To the right side of the URL bar, there is a small plus (+) symbol. When you click on it, you will see a dialog box appear, asking “Do you want to install the app?”, with a blue install button at the bottom.


If you click on the install button you will see an icon for your PWA installed on your desktop. When you double click on the icon, your PWA will open on your computer. Below is a screenshot of the installed icon on the desktop to the left and the website that has now been turned into a PWA to the left open after double-clicking on the installed icon. 


How to test PWA performances


To uninstall the PWA icon from your desktop screen do as indicated below. Click on the address bar on the three dots to the right, near the minimize (-) symbol. A dialogue box appears with the prompt ‘Avinstallera Wiredelta PWA..’ on the fourth line from the top – translated as ‘uninstall Wiredelta PWA…’ Click on the prompt and that’s it, the PWA icon will be uninstalled and gone from the desktop screen.


PWA testing tools

Step 4 – Test your PWA

Testing your PWA is an important step after how to turn a website into a PWA, as it is with any other type of application – mobile or desktop. So, for our Wiredelta PWA example, we tested its performance using Lighthouse from Google’s developer /inspection tools. This enables us to establish, among other things, how fast our PWA loads. 


Below is the google developer tools for those who have no idea what it looks like. In the Lighthouse section, under the device to the far right of the diagram click on the radio icon for what device you want to audit. There are only two choices – mobile or desktop. As seen below we have selected a mobile device. Then click generate report highlighted in blue just below the windmill icon.


PWA perfomance tests


Here are four screenshots of our simple Wiredelta PWA 2020 audit results. The first two screenshot results are for the mobile device with a performance of 76 out of 100. Which is great.While the last two screenshot results are for the desktop device which stands at 93 out of 100 loading at 0.3s which is epic! 


However, the most important results are screenshot two and four titled speed evaluation. Remember a PWA must be fast and reliable on initial loading. Every evaluation should be green meaning satisfactory. If you ever have a red evaluation, you may still have work to do like troubleshooting as directed by Lighthouse.


Screenshot 1 -Wiredelta PWA 2020 mobile device performance.


PWA performance tests


Screenshot 2 – Wiredelta PWA 2020 mobile device speed evaluation (most important).


what are progressive web apps


Screenshot 3 – Wiredelta PWA 2020 desktop device performance.


How to create a progressive web app


Screenshot 4:Wiredelta PWA 2020 desktop device speed evaluation (most important).


How to build a pwa

Summing up

In a world where cross-platform development is rapidly taking over native development, Progressive Web Applications seem like the answer we have all been looking for. For those who want a PWA of their own, they are faster than native applications, easier to develop and maintain, and more affordable.


Moreover, they are more enjoyable for users as well, as they live in browsers, so they are easy to find and install, and they are super lightweight, saving a lot of storage space.


Not to mention that, if you follow this step-by-step guide, you will be able to turn a website into a PWA in no time. Whether you are building a new website, managing a modern platform, or a legacy system. But, if you still have questions, get in touch with us and our team will answer every one of them.


Source link

Check Also

Robots Everywhere: Robots in space exploration

We take a look at robots in space and how different types are helping us ...

Leave a Comment:

Your email address will not be published. Required fields are marked *