Full Download Progressive Web Apps With React Create Lightning Fast Web Apps With Native Power Using React and Firebase 1st Edition Scott Domes PDF
Full Download Progressive Web Apps With React Create Lightning Fast Web Apps With Native Power Using React and Firebase 1st Edition Scott Domes PDF
com
https://textbookfull.com/product/fullstack-react-native-create-
beautiful-mobile-apps-with-javascript-and-react-native-5th-edition-
devin-abbott/
textbookfull.com
https://textbookfull.com/product/react-quickly-painless-web-apps-with-
react-jsx-redux-and-graphql-1st-edition-azat-mardan/
textbookfull.com
https://textbookfull.com/product/love-s-someday-first-edition-robin-
alexander/
textbookfull.com
Advancing the Power of Learning Analytics and Big Data in
Education Advances in Educational Technologies and
Instructional Design 1st Edition Ana Azevedo
https://textbookfull.com/product/advancing-the-power-of-learning-
analytics-and-big-data-in-education-advances-in-educational-
technologies-and-instructional-design-1st-edition-ana-azevedo/
textbookfull.com
https://textbookfull.com/product/fractured-the-salvation-society-1st-
edition-rene-dani/
textbookfull.com
https://textbookfull.com/product/come-fix-you-a-plate-
cookbook-30-simple-chicken-recipes-for-home-cooks-1st-edition-lila-
thompson/
textbookfull.com
https://textbookfull.com/product/alternatives-to-conventional-food-
processing-andrew-proctor/
textbookfull.com
Progressive Web Apps with React
Create lightning fast web apps with native power using React and Firebase
Scott Domes
BIRMINGHAM - MUMBAI
Progressive Web Apps with React
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of
the information presented. However, the information contained in this book is sold
without warranty, either express or implied. Neither the author(s), nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78829-755-4
www.packtpub.com
Credits
A special thank you to Packt Publishing for giving me the chance to write this book,
and for Onkar and Shweta for assisting me on this journey. Check out
https://www.packtpub.com/ for an excellent selection of quality programming books.
Thank you to my technical readers: Warren Vosper, Mario Grasso, Andrew Hayter,
and Miodrag Vujkovic. A special thanks to everyone at MuseFind for their support
and feedback, and to my family and friends for their encouragement.
Lastly, thanks to you, the reader, for picking up this book. I hope you enjoy it. You
can follow me on Twitter and Medium as @scottdomes, or my website,
scottdomes.com
About the Reviewer
Amar Gharat focuses on developing creative and unique web applications using
LAMP, open source, and cutting-edge technology as well as delivering work on time
to meet the deadlines with dedicated team work.
He has a total work experience of 11 years, and has executed projects from design,
development, production, and support. He defines requirements and plans project life
cycle deployment.
He also has knowledge of SDLC and process models, and defines resources and
schedules for project implementation. He plans and schedules project deliverables,
goals, milestones, and tracking them to closure.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all
Packt books and video courses, as well as industry-leading tools to help you plan
your personal development and advance your career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our
editorial process. To help us improve, please leave us an honest review on this
book's Amazon page at https://www.amazon.com/dp/1788297555. If you'd like to join our
team of regular reviewers, you can email us at customerreviews@packtpub.com. We
award our regular reviewers with free eBooks and videos in exchange for their
valuable feedback. Help us be relentless in improving our products!
Table of Contents
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Creating Our App Structure
Setting the scene
The problem
The other problem
Beginning work
Why Progressive Web Apps?
Why React?
A rose by any other name
User stories
Application challenges
Instant loading
Push notifications
Offline access
Mobile-first design
Progressive enhancement
Let's get going
Our app skeleton
CSS and assets
Meta tags and favicons
What is npm?
Node setup
The dark side of npm
Project initiation
Installing React
Using React
Welcome to ReactDOM
Summary
2. Getting Started with Webpack
Our project structure
Welcome to Webpack
Bundling files
Moving our React
Shortcuts
Our Dev server
Webpack loaders
Our first ES6
Splitting up our app
Hot reloading
Building for production
Creating a custom script
Making an asset manifest
Summary
3. Our App's Login Page
What is a React component?
Controversies and Separation of Concerns
Class components versus functional components
Our second component
State in React
Reusing components
Summary
4. Easy Backend Setup With Firebase
What is Firebase?
Firebase gotchas
Setting up
Hiding our API key
Deploying Firebase
Authentication with Firebase
What is a promise?
Back to authentication
Code cleanup
Signing up
Saving our user
Event listeners
Lifecycle methods
Summary
5. Routing with React
The plan
Pages on pages
The React Router difference
Our ChatContainer
Installing React Router
Our BrowserRouter
Our first two Routes
Redirecting on login
Logging out
Detour - higher order components
Our third Route
Summary
6. Completing Our App
User stories progress
ChatContainer skeleton
Managing data flow
Creating a message
Sending a message to Firebase
Our message data
Loading data from Firebase
Displaying our messages
Message display improvements
Multiple users
Batching user messages
Scrolling down
React refs
Loading indicator
The Profile page
Summary
7. Adding a Service Worker
What is a service worker?
The service worker life cycle
Registering our first service worker
Checking for browser support
Listening for the page load
Registering the service worker
Logging out the result
Experiencing the service worker life cycle
Adding Firebase to our service worker
Naming our service worker
Summary
8. Using a Service Worker to Send Push Notifications
Requesting permission
Tracking tokens
Attaching a user to the token
Changing the user inside NotificationResource
Creating a new token
Updating an existing token
Sending push notifications
Writing our Cloud function
Sending to the tokens
Testing our push notifications
Debugging push notifications
Checking the Cloud Functions logs
Checking the Service Worker
Checking the tokens
Summary
9. Making Our App Installable with a Manifest
What is an app manifest?
Browser support
Making our app installable - Android
Manifest properties
Other properties
Linking our manifest
Making our app installable - iOS
App install banners and you
Delaying the app install banner
Listening for the event
Summary
10. The App Shell
What is progressive enhancement?
The RAIL model
Load
Idle
Animation
Response
Timeline
Measuring using the timeline
The Summary tab
Network requests
Waterfall
Screenshots
PageSpeed Insights
The app shell pattern
Moving shell HTML out of React
Moving CSS out of React
Moving the loading indicator
Summary
11. Chunking JavaScript to Optimize Performance with Webpack
The PRPL pattern
Push
Render
Pre-cache
Lazy-load
What is code splitting?
Webpack configuration
Babel stage 1
Conditional imports
Higher-order components
AsyncComponent
Route splitting
Lazy loading
Summary
12. Ready to Cache
What is caching?
The importance of caching
The Cache API
Methods
The asset manifest
Setting up our cache
The install event
Opening up the cache
Fetching the asset manifest
Parsing the JSON
Adding the relevant URLs to the cache
The fetch event
The activate event
Grab the list of cache names
Loop over them
Testing our cache
Summary
13. Auditing Our App
What is Lighthouse?
The criteria
The Audits tab
Our first audit
Evaluating the readout
Using the Lighthouse CLI
Serving our build folder
Using Lighthouse to assess the served page
Logging the results
Summary
14. Conclusion and Next Steps
Next steps
Learning resources
Case studies
Building the Google I/O 2016 Progressive Web App
AliExpress case study
eXtra Electronics case study
Jumia case study
Konga case study
SUUMO case study
Example applications
PWA.rocks
Flipboard
React Hacker News
Notes
Twitter
2048 Puzzle
Articles to read
Native apps are doomed
A BIG list of Progressive Web App tips & tricks
Testing service workers
Twitter Lite and High Performance React Progressive Web Apps at Scale
Why are App Install Banners Still a thing?
A Progressive Web Application with Vue JS
Transforming an existing Angular application into a Progressive Web App
Progressing the Web
Designed Degradations - UX Patterns for Hostile Environments
Instant Loading Web Apps With An Application Shell Architecture
Trick users into thinking your site's faster than it is
Apple’s refusal to support Progressive Web Apps is a detriment to the future of th
e web
Tools
Workbox
Sw-precache
Sw-toolbox
Offline-plugin
Manifest-json
Serviceworker-rails
Sw-offline-google-analytics
Dynamic Service Workers (DSW)
UpUp
Generator-pwa
Progressive-webapp-config
Stretch goals
Switch to Preact
Show online status
Show when typing
Include file upload
Create chat rooms
Interactive without React
Building your own backend
Closing words
Summary
Preface
Progressive Web Apps with React aims to give you everything you need to know
about the future of web development. Progressive Web Apps (PWAs) are
becoming more and more common for companies looking to leverage the best the
web can offer, powered by cutting-edge technologies that bridge the gap between
web apps and native apps.
In this book, we'll leverage the power of the popular JavaScript library React.js to
create a fast and functional UI. Then, we'll add Progressive Web App features such
as push notifications and instant loading, using revolutionary new web technology.
Finally, we'll streamline our app's performance and look at how to best measure its
speed.
By the end of this book, you will feel comfortable with both React and PWAs, and
be ready for the future of the web.
What this book covers
Chapter 1, Creating Our App Structure, gives a brief overview of what exactly you
will be learning to build-- a real-time chat application with push notifications and
offline support. You will get to learn about the challenges that such an app presents,
and get a brief overview of the technologies that will be discussed in this book. By
the end of the chapter, you will set up the application structure of a chat app, with
HTML and CSS.
Chapter 2, Getting Started with Webpack, says that before you write any React code,
you need to set up the webpack build process. In this chapter, you will be introduced
to webpack; you will learn to install the package and set up some basic configuration
as well as get the development server running. This chapter will get you ready to
jump into React.
Chapter 3, Our App's Login Page, introduces you to React time! In this chapter, you
will learn to write the first two components: an App wrapper to contain the
application and a LoginContainer. Learn about rendering with ReactDOM and JSX,
and write a basic form to allow the users to log in. By the end of this chapter, you
will be familiar and comfortable with the React syntax.
Chapter 4, Easy Backend Setup With Firebase, informs that the login form looks great,
but is lacking actual functionality. To move forward, you will need a backend
database and authentication solution to communicate with it. This chapter will
introduce you to Firebase by Google. Set up the application on the Firebase console,
and then program the login and signup functionality for the form.
Chapter 5, Routing with React, lets you know that once the user logs in, you want to
redirect them to the main chat view. Therefore, in this chapter, you will learn to build
that main view and then set up the React Router that allows the users to move
between the pages. Lastly, learn to add a third view the individual user view--and
explore parameter matching in URLs.
Chapter 6, Completing Our App, takes you through the last step in building the basic
application, adding functionality to the chat and user views. You will learn to write
and read data from Firebase, taking advantage of React life cycle methods to do so.
Once that’s done, your web application will be complete, but it’s not quite
progressive yet!
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 7, Adding a Service Worker, covers service workers and how they work.
Here, you'll understand how to register a custom service worker and learn about its
life cycle, and then hook into the default Firebase messaging service worker.
Chapter 9, Making Our App Installable with a Manifest, teaches that a manifest is a
JSON file that allows users to save your app to their home screen. You will learn to
create the manifest and understand the best practices as well as iOS-specific
considerations. You will also learn to customize your splash screen and icons.
Chapter 10, The App Shell, puts across the point of the App Shell pattern being a key
concept in PWAs, but what advantages does it bring? You will be introduced to both
the shell and the RAIL system of progressive enhancement, and then move some of
you app's layout out of React for optimal rendering.
Chapter 12, Ready to Cache, walks through how you can leverage the service worker
to achieve offline capability, by understanding the new Cache API, and how to use it
with your service worker to cache the JavaScript chunks.
Chapter 13, Auditing Our App, says it's now time to check our work! In this chapter,
you will be introduced to Lighthouse and understand how to audit PWAs with
Lighthouse.
Chapter 14, Conclusion and Next Steps, Your first PWA is complete! In the
development process, you built most of the PWA infrastructure manually. In this
chapter, you will get to learn about the helper libraries and shortcuts to save time,
and you'll also explore the future of PWA development. Additionally, you will come
across suggestions about the future project ideas and improvements that can be made
to your chat app, as an extra challenge.
What you need for this book
All you require is a computer that can run Node.js (https://nodejs.org/en/download/), a
text editor for writing code, and the latest version of the Chrome browser. If you
want to test your application on mobile, you'll also need an Android or iOS phone.
Who this book is for
This book is for JavaScript developers who want to develop high-performance Web
User interfaces. This book requires basic knowledge of HTML, CSS and JavaScript.
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning. Code words in text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown
as follows: Inside App.js, we first import the LoginContainer.
When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
if (module.hot) {
module.hot.accept('./components/App', () => {
const NextApp = require('./components/App').default;
ReactDOM.render(
<App/>,
document.getElementById('root')
);
});
}
New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: Flip back
to the app, and you should see the Hello from LoginContainer of our
new component.
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.