<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joseph Ismail on Medium]]></title>
        <description><![CDATA[Stories by Joseph Ismail on Medium]]></description>
        <link>https://medium.com/@ismail.jsph?source=rss-144049e2576b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*WnElZ21E8pgWlpeaz59TvA.jpeg</url>
            <title>Stories by Joseph Ismail on Medium</title>
            <link>https://medium.com/@ismail.jsph?source=rss-144049e2576b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:23:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ismail.jsph/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Introduction to PWA set up]]></title>
            <link>https://medium.com/becode/introduction-to-pwa-set-up-660df31934f2?source=rss-144049e2576b------2</link>
            <guid isPermaLink="false">https://medium.com/p/660df31934f2</guid>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[progressive-web-app]]></category>
            <category><![CDATA[website]]></category>
            <dc:creator><![CDATA[Joseph Ismail]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 13:35:53 GMT</pubDate>
            <atom:updated>2019-04-30T19:13:11.308Z</atom:updated>
            <content:encoded><![CDATA[<h4>Practical guide to make it work for your first website</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q4rg4FqijsNeLUEqyUGcdA.jpeg" /></figure><p>I will give here a brief explanation on how to optimise (well, at least the way I made it work for my first website) your PWA score from the <a href="https://developers.google.com/web/tools/lighthouse/">Google Lighthouse</a> audit.</p><p>When I ran my first Lighthouse audit, I noticed multiple warnings concerning the PWA set up. I managed to solve most of them (like the requirement for https instead of http, some required meta tag attribute, …) but I ended up struggling with the concepts of <strong><em>manifest.json</em></strong> and <strong><em>service worker</em></strong> as it was the first time I heard those words. If it is the same for you, then this article <em>might</em> help.</p><p>Here’s what<a href="https://developers.google.com/web/progressive-web-apps/"> Google’s official introduction</a> says:</p><blockquote>Progressive Web Apps are user experiences that have the reach of the web, and are:</blockquote><blockquote>* Reliable — Load instantly and never show the downasaur, even in uncertain network conditions.<br>* Fast — Respond quickly to user interactions with silky smooth animations and no janky scrolling.<br>* Engaging — Feel like a natural app on the device, with an immersive user experience.<br>This new level of quality allows Progressive Web Apps to earn a place on the user’s home screen.</blockquote><p>In other words, the PWA allows you to make your website behave just like an application on smartphones, even <em>after</em> you loose internet connection.</p><p>As I said, the challenge for me was to set up something called the <strong><em>manifest.json</em></strong> and <strong><em>service worker</em></strong>.</p><ul><li>The manifest.json is a file that will handle your favicons i.e. it will handle the images (icons, logo, …) you want to use as icons of the user application, across the various operating systems (Android, iPhone, windows 8 and 10).</li><li>Service workers allow the user to access your website <em>after</em> internet connection is lost! Basically, you define the files (e.g. a specific script.js, or a dedicated index.html) to save up in the cache of the user browser and which will be used if the user looses internet. Note the <em>after </em>here, as the user has to access the website at least once with internet connection in order to save up the defined files in the cache of the browser.</li></ul><p>Here is my <a href="https://github.com/Fesouille/bootstrap-resto-website">github repository</a> of my first website set up for PWA so that you can follow this tutorial alongside with the code and files that made it work.</p><p>So let’s begin!</p><h3>Set up the manifest.json</h3><p>You can directly generate your favicons and the required files (which will constitute the manifest.json) thanks to dedicated website. Here are the two ones I worked with:</p><ul><li><a href="https://www.favicon-generator.org/">https://www.favicon-generator.org/</a> : I personally used this one to generate my manifest.json.</li><li><a href="https://realfavicongenerator.net/">https://realfavicongenerator.net/</a> : I then used this one to check up if my website was meeting the manifest.json requirements, but I noticed later that this one actually generates the file as well.</li></ul><p>You can thus upload the pictures you want to use as the app favicons (like your logo), and these sites will generate the followings files:</p><ul><li>A folder containing your uploaded image in multiple formats (for apple, android, windows 8 &amp; 10) and in multiple sizes,</li><li>a file <strong><em>manifest.json</em></strong>,</li><li>a file <strong><em>browserconfig.xml </em></strong>(from my understanding, this file is required for windows 8 and 10 devices),</li><li>and a code to incorporate into your HTML <em>&lt;head&gt;…&lt;/head&gt; </em>in order to reference all these files<em>.</em></li></ul><h4>Warning</h4><p>These generators do not guess where you will save these generated files and folder and thus assume the source (for generating the path) is the root of your website! If you save the files in the root, then you’re good to go. If not (this is particularly relevant in case you publish you site with a github page), consider this:</p><blockquote>Be sure to correctly reference your files !</blockquote><p>Example (based on my <a href="https://github.com/Fesouille/bootstrap-resto-website">PWA website</a>):</p><ul><li>My <em>index.html</em> is in my main folder named “ <em>bootstrap-resto-website</em>” (i.e. my repository)</li><li>Once the files were generated by the generator, I saved them in a <em>favicons folder</em>, which was saved in the <em>assets folder</em>.</li><li>Nevertheless, the generator proposes me to copy the following code (I show you here a sample) in the <em>&lt;head&gt;…&lt;/head&gt;</em> of my <em>index.html </em>as it supposes you saved everything in the root. Please note the <strong><em>href</em></strong> value:</li></ul><pre>&lt;link rel=”apple-touch-icon” sizes=”57x57&quot; href=”<strong>apple-icon-57x57.png</strong>”&gt;</pre><ul><li>If you haven’t saved the generated files in your root (like me), <strong>be sure to specify the correct path for your files</strong>. As a result, my code becomes:</li></ul><pre>&lt;link rel=”apple-touch-icon” sizes=”57x57&quot; href=”<strong>assets/favicons/</strong>apple-icon-57x57.png”&gt;</pre><ol><li>You have now to correct the path in all code lines generated by the generator</li><li>Open the <strong><em>manifest.json</em></strong> file and make sure to correct the path specified in this file as well. Here please note the the double slash<strong> \/ </strong>and begin your path with your main file (in my case, “ <em>bootstrap-resto-website</em>”). So that you have something like this:</li></ol><pre>“src”: “<strong>\/bootstrap-resto-website\/assets\/favicons\/</strong>android-icon-36x36.png”</pre><p>3. You have to specify the path to access the <strong><em>browserconfig.xml</em>. </strong>By default, the browser considers this file is for sure saved in your root and as a result, the generator does not generate the code line to access it. You have then to add it manually (I personally write it right after the declaration of the manifest.json… <a href="https://github.com/Fesouille/bootstrap-resto-website/blob/master/index.html">check out my code</a>):</p><pre>&lt;meta name=”msapplication-config” content=”<strong>assets/favicons</strong>/browserconfig.xml”/&gt;</pre><p>So that should be it for the <strong><em>manifest.json</em></strong> story! You will probably have some other error messages from the Lighthouse audit or from the analysis of the <a href="https://realfavicongenerator.net/">favicons generator</a>, but you should be able to overcome them (if not, hopefully I am not dead yet to help you out).</p><h3>Set up the Service Worker</h3><p>In order to understand (more or less) this concept, I kind of read that <a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers">article</a>.</p><p>Note that some open source solutions exist which set up the service worker for you (for example, <a href="https://www.talater.com/upup/getting-started-with-offline-first.html">upup</a>). Nevertheless, I did not manage to make it work properly 😞. If you manage to use these solutions, good for you! If not, you can try to set it up manually, just like I did.</p><p>You can then focus on the <a href="https://mdn.github.io/sw-test/">Star Wars demo</a> from the article. It helped me quite much to set up my service worker (and it gives some interesting tips on how to test the service worker directly from the browser console, which I will not cover here).</p><p>So let’s begin. To make it simple, there are three steps to set it up:</p><h4>1. Create a file “<strong>sw.js”</strong>, where you can copy the following code</h4><pre>this.addEventListener(‘install’, function(event) {</pre><pre>  event.waitUntil(</pre><pre>    caches.open(‘v1’).then(function(cache) {</pre><pre>      return cache.addAll([</pre><pre><strong>        ‘/bootstrap-resto-website/’,</strong></pre><pre><strong>        ‘/bootstrap-resto-website/offline/acceuil_offline.html’,</strong></pre><pre><strong>        ‘/bootstrap-resto-website/index.html’,</strong></pre><pre><strong>        ‘/bootstrap-resto-website/carte.html’,</strong></pre><pre><strong>        ‘/bootstrap-resto-website/gallerie.html’,</strong></pre><pre><strong>        ‘/bootstrap-resto-website/restaurants.html’,</strong></pre><pre><strong>        ‘/bootstrap-resto-website/contact.html’,</strong></pre><pre><strong>        ‘/bootstrap-resto-website/assets/img/failed_download.png’,<br>      </strong>]);<br>    })<br>  );<br>});</pre><pre>this.addEventListener(‘fetch’, function(event) {<br>  <br>  event.respondWith(<br>    <br>    caches.match(event.request).then(function(response){<br>      // caches.match() always resolves<br>      // but in case of success response will have value</pre><pre>      if (response !== undefined) {</pre><pre>        return response;</pre><pre>      } else {</pre><pre>        return fetch(event.request).then(function (response) {<br>          // response may be used only once<br>          // we need to save clone to put one copy in cache<br>          // and serve second one</pre><pre>          let responseClone = response.clone();</pre><pre>          caches.open(‘v1’).then(function (cache) {</pre><pre>            cache.put(event.request, responseClone);</pre><pre>          });</pre><pre>          return response;</pre><pre>        }).catch(function () {</pre><pre>          return caches.match(‘<strong>/bootstrap-resto-website/assets/img/failed_download.png’</strong>);<br>        });<br>      }<br>  }));<br>});</pre><ul><li>The first <strong>bold </strong>part includes the files that the service worker will save in the cache of the users browser. It should basically include your <em>index.html</em>, your <em>additional pages</em>, your <em>images</em>, your <em>style.css</em>, …</li><li>The second <strong>bold </strong>part (at the bottom of the code) can be considered your default element to display in case a file is missing in the cache. For example, I included the file <em>gallerie.html</em> to be saved in the cache. This page is supposed to display some pictures. But in case the pictures were not saved in the cache before internet connection is lost, the browser will not find the pictures to display and will, by default, display <strong><em>failed_download.png</em></strong>. Note that I specified this file twice: first in the part to specify the files to save in the cache, and second in the part to specify which file to use by default.</li><li>You can now include the files that <strong><em>you</em></strong> want to save in the cache of the user browser and that will be used <em>after</em> internet connection is lost. The browsers consider that the path of the files begins at the root, so if you are hosting your site with a github page like me, make sure to begin your url with you main folder name i.e. your repository name.</li></ul><h4>2. At the beginning of your “<em>script.js”, you should add the following code</em></h4><pre>// register service worker — BEGINNING</pre><pre>if (‘serviceWorker’ in navigator) {</pre><pre>  navigator.serviceWorker.register(‘<strong>/bootstrap-resto-website/sw.js’</strong>, {scope: ‘<strong>/bootstrap-resto-website/</strong>’}).then(function(reg) {</pre><pre>    if(reg.installing) {</pre><pre>      console.log(‘Service worker installing’);</pre><pre>    } else if(reg.waiting) {</pre><pre>      console.log(‘Service worker installed’);</pre><pre>    } else if(reg.active) {</pre><pre>      console.log(‘Service worker active’);<br>    }</pre><pre>  }).catch(function(error) {<br>    // registration failed</pre><pre>    console.log(‘Registration failed with ‘ + error);<br>  });<br>}</pre><pre>// register service worker — END</pre><ul><li>This part of code will check if the user browser supports a service worker and act accordingly.</li><li>Make sure again to specify the path to your files considering you are in the root.</li></ul><h4>3. As you should be used to, call your “script.js” from your “index.html”</h4><pre>&lt;script src=”assets/js/script.js”&gt;&lt;/script&gt;</pre><p>This way, your <strong><em>index.html</em></strong> will call your <strong><em>script.js</em></strong>, which will (in case the user browser supports the service worker) call your <strong><em>sw.js</em></strong>, which will save all the specified files in the cache.</p><p>And here it is! Your service worker should be set up 😎</p><h3>Conclusion</h3><ul><li>I made it brief here, so you will surely have to haggle !</li><li>You will encounter quite a few problems 😑 (<em>tip</em>: if nothing works as expected, try to delete all the cache and service workers of your browser and try again).</li><li>But you will overcome them ! 😁✌</li><li>Once it is all done, you can try by opening the website on a smartphone (better to use a last generation device), and select the option to “<em>add it to your homescreen.</em>” You should see it appears, opens and acts just like an app! 👏</li><li>I hope I can still be available to help you out, in addition to many tutorials you can probably find on the holy web.</li><li>This was my first experience with PWA setup (and my first Medium article), I cannot claim it was perfectly set up. If you have comments, critics, advises,… do not hesitate to reach out 🐱‍🏍</li></ul><h3>Useful Links</h3><ul><li><a href="https://github.com/Fesouille/bootstrap-resto-website">My github repository of my first PWA website</a></li><li>Favicons and manifest.json generator: <a href="https://www.favicon-generator.org/">generator 1</a>, <a href="https://realfavicongenerator.net/">generator 2</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers">Complete Service Worker tutorial</a> (and <a href="https://mdn.github.io/sw-test/">demo used</a>)</li><li><a href="https://www.talater.com/upup/">Upup website</a> (open source solution for service worker)</li><li><a href="https://www.linkedin.com/in/joseph-ismail-69a39714a/">My LinkedIn</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=660df31934f2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/becode/introduction-to-pwa-set-up-660df31934f2">📃 Introduction to PWA set up</a> was originally published in <a href="https://medium.com/becode">BeCode</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>