For this app to work we will need to expand service worker functionality
What is a service worker? https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
See article
https://www.captechconsulting.com/blogs/my-experience-using-service-workers
An example of Expanded Install and Fetch Event Functionality:
this.addEventListener(‘install’, function(event) {
event.waitUntil(
caches.open(‘movieCacheV1’).then(function(cache) {
return cache.addAll([
‘/’,
‘/index.html’,
‘/src/app.js’,
‘/src/movieRest.js’,
‘/src/styles/movieCheck.css’,
‘/src/styles/pure-min.css’,
‘/mymovies’ //Now I can easily cache my list of movies!
]);
})
);
});
This code pulls list of list movies on cache
This could be expanded to different things
*pull cards of saved stops from memory cache
*pull cards of saved X from memory of cache
*let's call these service workers feature-service-workers
It looks like for every feature there will need to be an installed service worker. This is how we can emulate modular functionality in the cards ie user picks which features to install.
Is it possible to have a service worker that allows you to choose which service workers to enable?
The functionality for this is for this reason:
Say they are 10 features. The user only wants 2. There PWA should be functional such that if they were going to select 2 only those 2 service workers should be grabbing data from the API.
Possible implementation of the theory:
-
Load all feature-service-workers. Based on user selection, the user 'activate' service worker though some trigger (ie feature1=true), then through if-else statements the service worker for the feature is installed
-
Feature installation that caches scripts with local storage
Bing and Google do this already. How we would use it: essentially a user can select a feature, the script of this feature is downloaded then saved to cache, and is then activated. Then whenever the user opens app the service worker is already installed so if fetches data
Essentially we would be using crosssite scripting. This is often used by hackers to exploit security vulnerabilities in APIs
https://addyosmani.com/basket.js/
Pros/Cons
Method 1:
Pros: load all features -> they are ready to activate with little to no downtime, straight forward to code, good for prototyping,
Cons: more features being added = more javascript code being loaded that user doesn't need = slower web app, no bueno
Method 2:
Pros: only load javascript for user selected features, add modularity to app while keeping it lean, use hacking abilities for the greater good (lol) makes this app seem cooler than just showing bus data
Cons: we have to build the bus data API to be 'hackable' to access data so that different implementations of cross-site scripting work. Cannot be hackable to manipulate data (but why would anyone want to do that with bus data?). Essentially anything dealing with user data will need to be in a seperate API for security reasons = more code for us, harder to do (aka we gotta be wicked sma-ht to pull this off elegantly), we will have to outsource payment API for security reasons and all other APIs we build that we don't want hacked will need to be built like fort knox.
In short:
Method 1: Easier to code, performance will possibly degrade over time
Method 2: Harder to code, performance will be affected by the number of service-worker-features installed by the user