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

Added support for CustomStrategy and Added IgnoreRoutes Option. #71

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

AFM-Horizon
Copy link
Contributor

@AFM-Horizon AFM-Horizon commented Feb 6, 2020

Hi Mads and Team,
I have added in support for a CustomStrategy.
This strategy is user defined through a customserviceworker.js file and allows users to create the file and supply whatever behaviour they desire.
I implemented this as I have noticed many requests to add various features to the different caching strategies and thought that this would be a more manageable alternative.

I have also added in a IgnoreRoutes option that allows users to define a list of routes that they dont want cached or want to treat differently. Please note that I have not changed any of the existing strategies, I have only supplied the option so that it can be used in the CustomStrategy and potentially in future updates if this behaviour should need to be added to a new caching strategy etc in fututre.

Please let me know if there are any issues or changes you would like to see!

Regards
Alex

N.B - The Json schema is out of date (it is missing a few of the newer features) and needs to be updated to reflect this. (currently it throws validation errors however they can be ignored as you know)

@dmanter
Copy link

dmanter commented May 29, 2020

I added a customserviceworker.js file with this code
self.addEventListener('sync', function (event) {
console.log("Sync");
if (event.tag == 'myFirstSync') {
event.waitUntil(doSomeStuff());
}
});
But in Chrome when I look at the service workers under application and hit the Sync button nothing happens.
What am I doing wrong?
Thanks!
Sync

@AFM-Horizon
Copy link
Contributor Author

@dmanter Hi!,
Have you cloned my fork of the project? This functionality has not been accepted into the main branch as of yet. It won't be available in the nuget package if you are using that! Apologies

@dmanter
Copy link

dmanter commented Jun 1, 2020 via email

@AFM-Horizon
Copy link
Contributor Author

@dmanter
Is your manifest json file formatted like the one shown in the Readme? make sure it is at the root (not in any folders) and named correctly and just try using the example one from the readme in your app for testing. (also make sure it references the two image icons required 512X512 and 192X192).
I haven't had any issues with the manifest while following these instructions so just double check that again.

In response to your error in the service worker from chrome. If it is with the cache.addAll or cache.put being undefined there is a known bug causing this issue
https://stackoverflow.com/questions/46375466/cache-in-service-worker-is-undefined
Try running the app in Firefox and see if the issue persists.

Just to reiterate there is no functionality available to edit or change the java script files that provide the underlying cache strategies at this point. If you need this functionality I would recommend either forking the repo and making the changes you require (It is not really super complex and is pretty well organized!) or you can try forking my branch and creating a customserviceworker. (you will obviously need to host the nuget package yourself or run it in your project)

Let me know how you go!

@dmanter
Copy link

dmanter commented Jun 1, 2020 via email

@AFM-Horizon
Copy link
Contributor Author

AFM-Horizon commented Jun 2, 2020

@dmanter
Sorry to hear it's still happening! I'm not sure what else to suggest. :(
Creating your own P.W.A App is not overly difficult! The only requirements as such are the manifest, service worker, Icons and HTTPS I believe. Most of the complicated parts in this project are configuration settings and file imports as well as the caching strategies. Again these are easy to find online on google and firefox etc and are standard strategies.
Good luck with your learning I'm sure you will find it to be quite an easy option building it yourself and building in the functionality you require as you go!

@dmanter
Copy link

dmanter commented Jun 2, 2020 via email

@madskristensen madskristensen merged commit f67af55 into madskristensen:master Jun 3, 2020
@madskristensen
Copy link
Owner

Thanks

@madskristensen
Copy link
Owner

A new version containing this feature will be available on NuGet within the next 30 minutes

@AFM-Horizon
Copy link
Contributor Author

Great! Thanks for the merge! I'll keep an eye out for any issues reoprted with the changes moving forwards.

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.

3 participants