Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Progressive Web Applcations

Progressive Web Applcations

This is an initial workshop for the Progressive Web Application for the NG/JS Algeria Meetup

Houssem Yahiaoui

May 28, 2016
Tweet

More Decks by Houssem Yahiaoui

Other Decks in Programming

Transcript

  1. “ Progressive Web Applications take advantage of new technologies to

    bring the best of mobile sites and native applications to users. They're reliable, fast and engaging.
  2. - Works Everywhere | offline in most situations - Push

    Notifications - Instantly Loaded - Simply Fast - One Tap Away - Looks Great Everywhere
  3. BUT

  4. Service Workers The service worker is a generic entry point

    for event-driven background processing in the Web Platform that is extensible by other specifications. - W3C
  5. Hint : Install event is the 1st one -> thing

    of something creative ! self.addEventListener('install', function(event) { console.log(‘Hi There !’); }); JS PS : I we don’t listen to the event, it will do nothing, simply pass it to the next one, then to the next one until the Pipe line got filled !
  6. self.addEventListener(‘activate', function(event) { console.log(‘Activated!’, event); }); self.addEventListener(‘fetch', function(event) { console.log(‘Let’s

    get some Data’); console.log(event.request.url); }); self.addEventListener(‘push', function(event) { console.log(‘Waiting for Push MSGs !’); }); JS
  7. self.addEventListener(‘activate', function(event) { event.waitUntil( caches.open('proapp').then( function(cache) { return cache.addAll([ '/',

    '/index.html', '/index.html?homescreen=1', '/?homescreen=1', '/styles/main.css', '/scripts/main.min.js', '/sounds/airhorn.mp3' ]) }) ); });
  8. Hint : Our App is fully Configured to host our

    Notifications! { “name” : “Application Name”, “gcm-sender_id” : “Project ID” } JSON PS : Add the code above to the manifest.json file (will get there in seconds ;))
  9. Hint : This will Do something in our Browser !

    navigator.serviceWorker .register('sw.js') .then( function(reg) { console.log(‘Hello There !’, reg); reg.pushManager.subscribe({ userVisibleOnly: true }).then( function(sub) { console.log(‘endpoint:’, sub.endpoint); }); }); JS
  10. Hint : Usual We Use a Web Portal | Notification

    Manager ! curl --header “Authorization: key=App_Secret_Key” --header “Content-Type: application/json” https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"Local ID\"]}" CURL PS : I used CURL (available in Linux/MacOS Easily configured in WinOS) to launch the GCM call !
  11. WEB M ANAFEST A JSON file that let our Web

    Application, a Mobile Like one in term of : 1 – Home Screen Presence. 2 – Splash Screen Presence. 3 – Short Naming. 4 – Application Starting Point.
  12. { "name": "NG/JS Algeria Meetups", "short_name": "NG/DZ", "background_color": "#3B3838", "display":

    "standalone", "orientation": "portrait", "Scope": "/", "start_url": "/", "icons": [ ] } NG/DZ
  13. Q/A