Offline-first PWA con Firebase y Vue.js

Similar documents
Eme03. Mobilise your Applications as Progressive Web Apps

More on Testing and Large Scale Web Apps

תוכנית יומית לכנס התכנסות וארוחת בוקר

Service Workers & APEX

Vue.js Developer friendly, Fast and Versatile

Full Stack boot camp

Getting Started with ReactJS

Web Push Notification

Build Native-like Experiences in HTML5

Quick Desktop Application Development Using Electron

Web Development for Dinosaurs An Introduction to Modern Web Development

High Performance Single Page Application with Vue.js

Clearing Cache for NAVBLUE Web App

Developing ASP.NET MVC Web Applications (486)

Web Performance in

Course 20480: Programming in HTML5 with JavaScript and CSS3

COURSE 20480B: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Programming in HTML5 with JavaScript and CSS3

Cisco Spark Widgets Technical drill down

"Stupid Easy" Scaling Tweaks and Settings. AKA Scaling for the Lazy

Copyright is owned by the Author of the thesis. Permission is given for a copy to be downloaded by an individual for the purpose of research and

PWA-ifying Santa Tracker. Sam

BIG-IP Access Policy Manager : Portal Access. Version 12.1

Webpack 2 The last bundler you would need in Vijay Dharap, Principal Architect, Infosys

Getting Started with the ArcGIS API for JavaScript. Julie Powell, Paul Hann

django-baton Documentation

Modern SharePoint and Office 365 Development

BUILDING HYBRID MOBILE APPS WITH ORACLE JET

How To Present Progressive Web Apps To Your Clients

Microsoft Programming in HTML5 with JavaScript and CSS3

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Angular 4 Syllabus. Module 1: Introduction. Module 2: AngularJS to Angular 4. Module 3: Introduction to Typescript

20480B - Version: 1. Programming in HTML5 with JavaScript and CSS3

Create-A-Page Design Documentation

CSCI 201 Google Chrome DevTools

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

FRONT END WEB. {< Course Details >}

Ionic CLI is the default and easiest way to work with ionic projects. In this tutorial we will learn the ins and outs of Ionic CLI.

Exploring Chrome Internals. Darin Fisher May 28, 2009

Lab 1 - Introduction to Angular

BIG-IP Access Policy Manager : Portal Access. Version 13.0

CSC309 Final Lecture

55249: Developing with the SharePoint Framework Duration: 05 days

ANGULAR 2.X,4.X + TYPESRCIPT by Sindhu

PWA s are the future!

WHAT IS NEW FOR DEVS IN SP 2013

20480C: Programming in HTML5 with JavaScript and CSS3. Course Code: 20480C; Duration: 5 days; Instructor-led. JavaScript code.

Nodes Tech Slides - Progressive Web Apps, 2018

Ten interesting features of Google s Angular Project

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes

Delete Browsing History

HTML5 Evolution and Development. Matt Spencer UI & Browser Marketing Manager

DEVELOPING MICROSOFT SHAREPOINT SERVER 2013 ADVANCED SOLUTIONS. Course: 20489A; Duration: 5 Days; Instructor-led

Firefox for Android. Reviewer s Guide. Contact us:

Techno Expert Solutions

20480B: Programming in HTML5 with JavaScript and CSS3

Programming in HTML5 with JavaScript and CSS3

Managing State. Chapter 13

Surrogate Dependencies (in

Debugging and optimization your RhoMobile Application Raghavendra KC

Release Notes: J-Web Application Package Release 15.1A1 for Juniper Networks EX Series Ethernet Switches

Fundamentals of Website Development

Stencil: The Time for Vanilla Web Components has Arrived

Programming in HTML5 with JavaScript and CSS3

Azure Development Course

Front End Nanodegree Syllabus

Getting started with Tabris.js Tutorial Ebook

Simple AngularJS thanks to Best Practices

Progressive Web Apps & Polymer. Wendy Ginsberg Product Manager,

Serverless Single Page Web Apps, Part Four. CSCI 5828: Foundations of Software Engineering Lecture 24 11/10/2016

d. Delete data e. Transactions Realtime Features a. Value Listener b. Child Listener c. Remove Listeners

Sweet Themes Are Made of This: The Magento PWA Studio

Developing Microsoft SharePoint Server 2013 Advanced Solutions

Single Page Applications

"Charting the Course... Comprehensive Angular. Course Summary

The Web, after HTML5. Jonghong Jeon. 9 December 2015

Senior Technical Specialist, IBM. Charles Price (Primary) Advisory Software Engineer, IBM. Matthias Falkenberg DX Development Team Lead, IBM

Adobe Marketing Cloud Best Practices Implementing Adobe Target using Dynamic Tag Management

EPUB in the Browser. Ben Walters Principle Software Engineering Lead at Microsoft

Developing Microsoft Azure Solutions

Developing Enterprise Cloud Solutions with Azure

Moving WebSphere Portal Themes into Watson Content Hub. WebSphere Portal Lab Services (SEAL) Team IBM

VMware AirWatch - Workspace ONE, Single Sign-on and VMware Identity Manager

70-532: Developing Microsoft Azure Solutions

Course 20486B: Developing ASP.NET MVC 4 Web Applications

Presented by. Dheepa Iyer Managing Consultant. Commissioned for. Reston SharePoint User Group. SharePoint Framework. May 2017

Developing ASP.NET MVC 4 Web Applications

Credits: Some of the slides are based on material adapted from

Chapter 1 - Development Setup of Angular

django-baton Documentation

Your essential APEX companion. Marko apexbyg.blogspot.com

Advance Mobile& Web Application development using Angular and Native Script

A JavaScript Framework for Presentations and Animations on Computer Science

What Mobile Development Model is Right for You?

Future Web App Technologies

ASP.NET MVC Training

Introduction to Sencha Ext JS

Guides SDL Server Documentation Document current as of 04/06/ :35 PM.

Homework 8: Ajax, JSON and Responsive Design Travel and Entertainment Search (Bootstrap/Angular/AJAX/JSON/jQuery /Cloud Exercise)

Transcription:

Offline-first PWA con Firebase y Vue.js

About me Kike Navalon, engineer Currently working at BICG playing with data You can find me at @garcianavalon 2

We live in a disconnected & battery powered world, but our technology and best practices are a leftover from the always connected & steadily powered past. offlinefirst.org 3

Demo What are we going to build t3chfest2018.firebaseapp.com 4

1 The offline APIs for the web With a little history

6

Service Workers Javascript worker (no access to DOM) Run in the background Proxy between web page and network Programmatic control of caches and requests Evolution on top of Application Cache limitations and issues to give control to developers 7

Service Worker Web site HTML/JS Internet Cached resources 8

9

Web Storage Cookies v2.0 Session storage: cleans when browser closes Local storage: persistent after browser closing Useful for simple key-value pairs but not potent enough for large amount of data plus no Web Worker support 10

IndexedDB Structured data, including files/blobs Indexes for performant queries on the data Object-oriented DB Supports Web Workers Designed to provide rich queries regardless of network access and to store large amounts of data 11

1 Practice: the offline developer toolkit

1 1. Go to the demo app (t3chfest2018.firebaseapp.com) and open chrome developer tools 2. Use the application tab to view the service worker a. Experiment with the offline/online and unregistering the service worker. b. How many times do you need to refresh to have offline working? 3. Check the Clear Storage section a. What is consuming the most storage? b. Try clearing storage and reloading 4. Is the app using web storage? What do you think it is stored there? 5. Explore IndexedDB. Can you find where the actual contacts are stored?

1 6. Now go to the Cache Storage section a. Explore what resources are in the cache b. Look closely, do you find anything weird? c. Yes, two resources have content-length zero. Which ones? Why do you think it is? 7. Check the frames section a. You can see loaded resources by frame. 8. Change to the Network tab a. You can see the network requests and times for every resource b. Experiment with the throttle/offline option and hard-reloading the page. Can you see any difference in the timing breakdown? c. When does the page load faster, online or offline? 9. Finally, use the Audit tab to generate a Lighthouse report

2 Service Workers the easy way using Vue templates Webpack, sw-precache and firebase hosting magic!

Webpack 16

sw-precache Module for generating automatically a Service Worker Precaches resources: serves them cache-first Integrated with build process Detects all static resources and generates a hash -> changes in the files create a new hash Developed by Google Chrome Labs to make easier the App Shell pattern. github.com/googlechromelabs/sw-precache 17

Vue.js PWA template Full-featured setup with webpack, sw-precache, hot reloading and linters github.com/vuejs-tem plates/pwa 18

Firebase Hosting Full-managed static hosting with version control Free domain with SSL Production-ready with world-wide CDN Configurable Free Easiest and best web server for client-side rendering apps (and server-side rendering too using Cloud Functions) 19

NEVER CACHE YOUR SERVICE WORKER FILE 20

Firebase Hosting Conf to prevent sw caching 21

2 Practice: Creating the Vue.js PWA

2 1. Install the Vue CLI npm install -g @vue/cli 2. Run vue init pwa {project_name} and setup your app 3. Run npm run dev a. Go offline. What is happening? 4. Let s change the app a little a. Rename the Hello.vue component to Contacts.vue. Update router file too! b. Clean the html template in Contacts.vue c. Return an array called contacts in the data function. d. Contacts is an array of objects with properties name and email. Make up two or three fake contacts. e. Use v-for to go over the array and render the contacts. Use whatever HTML tags you prefer f. OPTIONAL: add some CSS to make it look better

2 1. Create firebase project in the firebase web 2. Install the Firebase CLI npm install -g firebase-tools 3. Configure Firebase hosting a. Public directory must be dist b. Add no-cache headers as explained before 4. Build your app: npm run build 5. Serve your app: firebase serve a. Is offline working? Use the application tab in the chrome dev tools to check what s going on 6. Now deploy to your hosting: firebase deploy a. Visit your app url and verify is all working correctly! 7. Try doing some changes to your app and deploying. a. Is your app updating properly? b. How many times do you need to refresh the page to see changes?

3 Offline data sin despeinarte Cloud Firestore to the rescue

Cloud Firestore Fully managed, NoSQL DB of hierarchical documents Expressive querying with indexing Flexible security rules Real-time events Automatic multi-region replication Easy offline data Evolution of famous Firebase Real-time database 26

More structured data Collection Document Document Document 27

Collection Docu ment Docu ment Docu ment With hierarchic Collection Collection relations Docu ment Docu ment Docu ment Docu ment Collection Collection Collection Docu ment Docu ment Docu ment Docu ment Docu ment Docu ment Docu ment Docu ment 28

3 Practice: Add Cloud Firestore for offline data

3 1. Create data in Cloud Firestore using the firebase web a. Create a contacts collection b. Add some documents using auto-id and with name and email string fields 2. Prepare the app a. Leave the contacts array empty b. Add a loading message using v-if if the contacts array is empty 3. Add firebase to your PWA a. npm install -s firebase b. Use main.js and follow firebase docs c. Remember that we are using a bundler!

3 4. Query the data a. Use the mounted lifecycle method b. Get all docs in contacts collection c. For every doc, add doc.data() to the component contacts list d. Vue reactivity system will render the list 5. Build and verify everything is working 6. Enable offline for firebase a. In main.js, after initialization b. Follow the firebase docs 7. Build and deploy. a. Is it working offline? b. Inspect IndexedDB, can you find your docs?

4 Closing thoughts TL;DL

Further work Offline write using Cloud Firestore Offline caching of media files Offline navigation inside app Performance: App shell and dynamic imports Push notifications App manifest... 33

Offline-first is a long road, with challenges and still under active development, but there are production-ready tools to help you. There are plenty of Offline-first PWAs success stories. Will yours be the next? 34

Thanks! Any questions? You can find me at @garcianavalon & garcianavalon@gmail.com Special thanks to all the people who made and released these awesome resources for free. Presentation template by SlidesCarnival 35