Skip to content

Project PWA Fire is an open source javascript and json bundle that allows you to convert your existing website into a progressive web app or build one in a few.

License

Notifications You must be signed in to change notification settings

PPFutureProjects/pwafire

 
 

Repository files navigation

Build amazing Web experiences now with PWA Fire. Github latest release version availabe HERE

Get Started with PWA Fire

Project PWA Fire is an open source Progressive Web App javascript and json Bundle developed by Maye Edwin that allows you to convert your website into a Progressive Web App or build one in a few.

It is the most simplest way you can ever convert your web app or website into a 100% Progressive Web App and still have some fun with the code. It doesn't make you a lazy code beast.

PWA Fire Logo

What to do first // Required

Download PWA Fire and from pwafire_bundle folder, upload the sw.js and manifest.json files to the ROOT folder of your project or website.

Be sure to edit the sw.js and manifest.json file as in the guide provided below to fit your web app needs.

N/B: Do not configure or edit anything else but the one guided to.

Configuration guide

1. Code to register the service worker

This is the first step to making your web app work offline. Copy and paste this code to your index file, eg just before the end of the body tag or in the head tag in html5

N/B : You need HTTPS

You can only register service workers on Websites, Web Apps or Pages served over HTTPS.

Read more about service workers HERE

<!-- register service worker -->
	<script>
	
	    if ('serviceWorker' in navigator) {
  window.addEventListener('load', function() {
    navigator.serviceWorker.register('/sw.js')
    .then(function() { console.log("Service Worker Registered"); });
  }
  
  );
}
        </script>
		<!-- end of service worker -->

This code checks to see if the service worker API is available, and if it is, the service worker at /sw.js is registered once the page is loaded.

2. Using the Web Manifest - manifest.json

When you have uploaded the manifest and it's on your site, add a link tag to all the pages that encompass your web app, as follows;

<link rel="manifest" href="/manifest.json">

Configuring the manifest.json helps you to specify how you want your web app to look like when launched on the device.

Read more about Web Manifest HERE

a) Service Worker // sw.js Guide

Follow the steps as commented in the code below in order to correctly configure the sw.js file.

//after a service worker is installed and the user navigates to a different page or refreshes, 
//the service worker will begin to receive fetch events
self.addEventListener('fetch', function(event) {
    event.respondWith(caches.open('cache').then(function(cache) {
        return cache.match(event.request).then(function(response) {
            console.log("cache request: " + event.request.url);
            var fetchPromise = fetch(event.request).then(function(networkResponse) {
                
                // if we got a response from the cache, update the cache
                
                console.log("fetch completed: " + event.request.url, networkResponse);
                if (networkResponse) {
                    console.debug("updated cached page: " + event.request.url, networkResponse);
                    cache.put(event.request, networkResponse.clone());
                }
                return networkResponse;
            }, function (e) {
                
           // rejected promise - just ignore it, we're offline
                
           console.log("Error in fetch()", e);
           e.waitUntil(
           caches.open('cache').then(function(cache) { // our cache here is named *cache* in the caches.open()
           return cache.addAll([ //cache.addAll(), takes a list of URLs, then fetches them from the server and adds the response to the cache.
          // add your entire site to the cache- as in the code below; for offline access
          // If you have some build process for your site, perhaps that could generate the list of possible URLs that a user might load.
          '/', // do not remove this
          '/index.html', //default
          '/index.html?homescreen=1', //default
          '/?homescreen=1', //default
          '/assets/css/main.css',
               
          // Do not replace/delete/edit the sw.js/ and manifest.js paths below
          '/sw.js/',
          '/manifest.js',

          // These are links to the extenal social media buttons that should be cached if any exists.
         'https://platform.twitter.com/widgets.js',
         'https://platform.linkedin.com/badges/js/profile.js',
         'https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.11&appId=128193484441134',
         'https://buttons.github.io/buttons.js'
      ]);
    })
  );    });
  
        // respond from the cache, or the network
            return response || fetchPromise;
     });
    }));
});

b) Web Manifest // manifest.json Guide

Follow the steps below as described in order to correctly configure the manifest.json file.

Configure/edit the background and theme colors, display type, the Web App short name, the Web App name, icons size (keep icon sizes as specified below) and your icon/logo paths. Also state the img type eg image/ico or image/png.

Leave the start url as recomended below though this can be anything you want; the value we're using has the advantage of being meaningful to Google Analytics.

{
  "background_color": "#fff",
  "display": "standalone",
  "orientation":"portrait",
  "theme_color": "#fff",           
  "short_name": "PWA Fire",
  "name": "PWA Fire Codelab",
  "icons": [
  {
  "src": "icons/pwafire512.png",
  "type": "image/png",
  "sizes": "48x48"
  },
  {
  "src": "icons/pwafire512.png",
  "type": "image/png",
  "sizes": "96x96"
  },
  {
  "src": "icons/pwafire512.png",
  "type": "image/png",
  "sizes": "192x192"
  }
  ,
  {
  "src": "icons/pwafire512.png",
  "type": "image/png",
  "sizes": "512x512"
  } 
  ],

  "start_url": "index.html?launcher=true"
  }

Also remember to add the theme color to all your pages as shown in the code below;

<!-- theme-color -->
 <meta name="theme-color" content="#fff" />
<!-- end-theme-color -->

Features //Roadmap

  1. Offline Capabilities and Add to Homescreen (Done!)

  2. Push notification add-on (In progress)

  3. Automatic PWA Fire Bundle Generator U/I for non developers (To begin)

  4. Propose your Feature by Creating an Issue

View Progressive Web Apps Built with Project PWA Fire

Progressive Web App Web App Link
Project Maye PWA View Now
Share Your Story View Now
PWA Fire PWA View Now
GDG Kenya View Now

Join the conversation

Follow Project PWA Fire on Twitter. Get Live Help on our Slack Workspace.

Communication Channel Talk to us
Live Twitter Chat Tweet us
Slack Workspace Join Workspace

License

MIT License | View License |

Support us

Donate a star, like, follow and contribute in any way. Be sure to use Project PWA Fire. If you use PWA Fire, kindly let us know via info@pwafire.org | mayedwine1@gmail.com or JUST simply Tweet us.

About

Project PWA Fire is an open source javascript and json bundle that allows you to convert your existing website into a progressive web app or build one in a few.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.4%
  • CSS 1.6%