Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service worker #210

Merged
merged 44 commits into from
Feb 7, 2022
Merged

Service worker #210

merged 44 commits into from
Feb 7, 2022

Conversation

rosemcc
Copy link
Contributor

@rosemcc rosemcc commented Jan 20, 2022

This PR adds PWA functionality to the ResearchHub, using the Angular service worker. A service worker is a script that runs in the web browser and manages caching for an application, by acting as a network proxy. Using a service worker to reduce dependency on the network can significantly improve reliability and performance of the app. In addition to caching improvements, having the app configured as a PWA also allows it to be installable on the user's device/platform, which can increase user engagement.

Service workers are supported in the latest versions of Chrome, Firefox, Edge, Safari, Opera, UC Browser (Android version) and Samsung Internet. IE and Opera Mini do not support service workers. Where service workers are not supported, the app will still run as normal, but without the added benefits of a service worker.

Proposed Changes

  • Addition of the following files to support service worker and PWA functionality:

    • ngsw-config.json - Angular service worker configuration. This file specifies the caching behaviours of the service worker including which file types and external resources to cache, and the install mode and update mode to use for different resources. It also configures caching policies for data (API) requests. We specify a policy for the graphql service with the 'freshness' strategy which means the service worker will preferentially fetch requested data from the network. Only if the network times out, (according to 'timeout' setting), does the request fall back to the cache. This makes sense for our purposes, as the app content could be updated at any time, so we ensure that the data displayed is always up to date with the CMS.
    • manifest.webmanifest - Web app manifest which configures the app name, theme color, preferred display settings, scope and start url, and specifies the location of app icons. This is the file which enables the app to be installed on a users device.
    • assets/icons - Series of app icons used for display on notifications and app installations, with different sizes to accommodate different devices/OS.
  • Updated app.module.ts to register and enable the service worker script, and added a bypass for 504 (gateway timeout) errors so that the service worker can attempt to serve cached files if there is a problem with the network connection (enable offline functionality of the app)

  • Updated angular.json to include the app manifest in the build

  • App manifest link and app theme color is added to index.html

  • Updated README

  • Added script to run the app in prod mode to enable testing service worker functionality locally (npm start:prod)

  • Update cloudfront secure-headers lambda function to include the app manifest, and modifications to connect-src policy for service worker requests (more info).

  • Added sw-updates.service.ts - manages updates to the app and user notifications, and handles error states, using the SwUpdate class.

  • Users are notified when a new version of the app is ready to install. The notification is an Angular Material snackbar

Additional changes/fixes

  • Cleaned up codeCoverageExclude array in angular.json
  • Fixed the 'about' link on the footer and fixed the unit test
  • Removed many unused Material modules from app.material.module.ts

@rosemcc rosemcc requested a review from Trombach January 23, 2022 22:07
@rosemcc rosemcc marked this pull request as ready for review January 23, 2022 22:07
@Trombach
Copy link
Contributor

Trombach commented Jan 24, 2022

This comment is pretty much just an FYI.

One minor issue we probably don't have to address can be viewed in the chrome dev tools under Application > Manifest
image

This is related to how a PWA is installable and certain platforms allow you to change the shape of the app launch icon. For those cases the provided icons have to be maskable https://web.dev/maskable-icon/

Given that the install-ability of the hub is only a side effect of this PR, it's not something we have to address. However, if someone decides to install the app there is a (low) chance that the icon will not look quite right.

Edit: Here is an example from installing the web app on an android phone that illustrates the issue:
Screenshot_20220124-151156

Copy link
Contributor

@Trombach Trombach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just some comments and one fix for the sw-update unit test.

Really cool stuff in here. The app looks awesome when installed and the update notification came through instantly. Nice work!

research-hub-web/src/index.html Show resolved Hide resolved
@rosemcc rosemcc requested a review from Trombach February 7, 2022 22:42
@rosemcc rosemcc merged commit 62a5f68 into master Feb 7, 2022
@rosemcc rosemcc deleted the service-worker branch February 7, 2022 23:00
@rosemcc rosemcc mentioned this pull request Feb 23, 2022
rosemcc added a commit that referenced this pull request Feb 24, 2022
* delete unused components

* show external links icons

* tweaks to card titles for consistency

* navigateTo changed to window.open, fix typo

* minor fixes

* close search autocomplete panel on enter keypress

* readme

* chore: version bump

* Bump nodemon from 2.0.12 to 2.0.15 in /cer-graphql

Bumps [nodemon](https://github.com/remy/nodemon) from 2.0.12 to 2.0.15.
- [Release notes](https://github.com/remy/nodemon/releases)
- [Commits](remy/nodemon@v2.0.12...v2.0.15)

---
updated-dependencies:
- dependency-name: nodemon
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* external links icon not on phone numbers

* fix link card external icon

* cards external links functionality and accessibility

* fix tabbing on contact card

* open assets in new tab

* dont show external link icon on home page banner content

* chore: add subhub-link-checker to dependabot.yml

* Bump contentful-export from 7.13.34 to 7.14.11 in /hub-search-proxy

Bumps [contentful-export](https://github.com/contentful/contentful-export) from 7.13.34 to 7.14.11.
- [Release notes](https://github.com/contentful/contentful-export/releases)
- [Commits](contentful/contentful-export@v7.13.34...v7.14.11)

---
updated-dependencies:
- dependency-name: contentful-export
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* npm update, lock @elastic/elasticsearch version to 7.13.0 due to breaking change in v7.14+

* Bump nodemon from 2.0.12 to 2.0.15 in /cer-graphql

Bumps [nodemon](https://github.com/remy/nodemon) from 2.0.12 to 2.0.15.
- [Release notes](https://github.com/remy/nodemon/releases)
- [Commits](remy/nodemon@v2.0.12...v2.0.15)

---
updated-dependencies:
- dependency-name: nodemon
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* updated dev dependencies

* more updates

* Persistent Notification (#202)

* added animation to notification

* 1st version remember persistant notification

* refactored notification request into service

* formatting

* code cleanup and comments

* minor fix to method description

* more changes to comments

* unit tests for getNotification() function

* removed some unused code from unit test

* added test for storeCurrentNotificationVersion

* improved close function

* removed focused describe

Co-authored-by: Rose <[email protected]>

* added filter counter to tab labels (#208)

* remove unused dependencies and use lockfile version 2 (#207)

* remove unused dependencies and use lockfile version 2

* update sentry to latest

* update rxjs, npm audit fix

* fix interface change to iif() in rxjs 7

* fix chunkload error

Co-authored-by: rosemcc <[email protected]>

* chore: add PR templates

* chore: generic PR template

* chore: delete separate PR templates

* Angular-13.1 (#211)

* update ng-mocks

* update @angular/cli

* update @angular/material @angular/core

* npm update

* removed workaround for mat-card-image on picture tags

* added missing mat-card-image directive

* fixed default images not rendered properly, minor re-factor

* minor tidy up

* update karma version

* Service worker (#210)

* ng add @angular/pwa

* set theme-color

* replace default Angular icons with UoA

* clean up codeCoverageExclude

* readme

* Material icons and fonts caching

* Revert "Material icons and fonts caching"

This reverts commit 14b2e3c.

* material icons, uoa fonts, contentful assets caching, readme

* lazy fetch contentful assets

* service worker on prod index.html

* App name

* add script to run in service worker mode locally

* csp update WIP

* 504 gateway timeout bypass

* sw updates service WIP

* note

* unit tests passing

* more csp updates due to service worker fetching

* about link fix on footer

* adding sw-updates functionality

* add nontransparent icon for apple-touch-icon

* replace deprecated methods, add error handling

* package-lock fix after merge

* tidying, add types

* material dialog for update confirmation

* tests passing

* Change dialog to snackbar, add styling

* add a test

* remove unused material modules

* button style

* minor update to script and readme for running service worker locally

* fix snackbar style

* add app id to manifest

* refactor swUpdates, add tests

* remove f

* add maskable icons

* icons fix

* add apple touch icon

* changes to pipe and unit test

* remove unused imports

Co-authored-by: Luke <[email protected]>

* Bump contentful-export from 7.14.11 to 7.14.27 in /hub-search-proxy

Bumps [contentful-export](https://github.com/contentful/contentful-export) from 7.14.11 to 7.14.27.
- [Release notes](https://github.com/contentful/contentful-export/releases)
- [Commits](contentful/contentful-export@v7.14.11...v7.14.27)

---
updated-dependencies:
- dependency-name: contentful-export
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump @graphql-codegen/typescript in /research-hub-web

Bumps [@graphql-codegen/typescript](https://github.com/dotansimha/graphql-code-generator/tree/HEAD/packages/plugins/typescript/typescript) from 1.23.0 to 2.4.3.
- [Release notes](https://github.com/dotansimha/graphql-code-generator/releases)
- [Changelog](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/typescript/CHANGELOG.md)
- [Commits](https://github.com/dotansimha/graphql-code-generator/commits/@graphql-codegen/[email protected]/packages/plugins/typescript/typescript)

---
updated-dependencies:
- dependency-name: "@graphql-codegen/typescript"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update for Terraform AWS Provider v4.0.0 (#225)

* s3 bucket config updates for provider v4

* add missing indices on secondary website bucket configs

* add version constraint for AWS provider

* Dependency cleanup (#229)

* remove nodemon and webdriver manager, remove unneeded script

* remove apollo-link

* remove aws4 and aws-sdk

* Merge branch 'master' into dependency-cleanup

* more unused deps

* update jasmine-core, npm audit fix

* package updates, fix ngx-markdown breaking change

* package-lock

* update sentry, date-fns

* update @angular/core to 13.2.3

* update @angular-eslint/schematics to 13.1.0

* added graphql devDependency for codegen

Co-authored-by: Lukas Trombach <[email protected]>

* Update subhub link checker deps (#226)

* Update versions

* Update f36 deps

* Update to use new methods

* Rewrite promises as async blocks

* Bump @types/react-dom version

* Run npm audit fix

* Add more instructions for deployment

* Add note about official release process

* Update package lock file to use v2
- Also remove unused imports

* Search Cards Linking Behaviour (#231)

* add anchor tag over whole card, fix title styling

* Update research-hub-web/src/app/components/search-page/search-results-list/search-results-list.component.html

Co-authored-by: Lukas Trombach <[email protected]>

* fix link

* fix link

Co-authored-by: Lukas Trombach <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lukas Trombach <[email protected]>
Co-authored-by: Luke <[email protected]>
Co-authored-by: Noel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants