Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

A gulp task to generate a list of files to precache #56

Closed

Conversation

jeffposnick
Copy link
Contributor

@ebidel @devnook & co.:

As an alternative to hardcoding a list of URLs that should be cached during the service worker's install event, this code takes the more flexible approach of generating that list via a gulp task, based on (a subset of) the actual files present on the server.

There's no concept of a "config" file for shed, so the code cobbles something together that gets loaded via importScripts when the service worker starts up. (Only the precache list is being generated right now, but in the future, if shed supports it, cache versioning could also be controlled via a similar approach and configured via gulp.)

The list of resources to be precached is very broad right now, and there's a TODO to investigate paring that down.

To make local developer saner, no files are precached when running the serve task, but you can override this behavior by manually running generate-shed-config-dev after serve.

@@ -48,6 +44,6 @@ if ('serviceWorker' in navigator) {
};
};
}, function(err) {
console.log(err);
console.error('Service worker registration failed:', err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a TODO to log this to GA.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this particular case, I don't think we'll get anything useful via GA logging—the only reasons why the register() call should reject are due to us messing something up (either trying to serve the sw.js script from an untrusted location, or pushing out a sw.js with a syntax error). Hopefully neither of those things will actually happen in the actual production environment.

As part of a larger question, how would logging this sort of thing fit into our overall GA strategy? I.e. what sorts of things should we be keeping track of, other than page views and performance metrics?

Copy link
Contributor

Choose a reason for hiding this comment

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

We setup a window.onerror handler for santa that reported any client-side errors in realtime to GA. That was fairly useful for catching bonehead mistakes we pushed. We can do the same for IOWA. It's pretty handy.

Copy link
Contributor

Choose a reason for hiding this comment

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

#77

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll abstract out the GA error logging into a helper that could be called from either window.onerror or explicitly from within a Promise rejection handler. I don't believe there's any global way to call such a helper function whenever any Promise rejects (and that could get very noisy, if there was), so we'll have to remember to explicitly add in the logging helper in Promise rejections.

@ebidel
Copy link
Contributor

ebidel commented Dec 24, 2014

Reviewed. Can you also add a section to the README

@jeffposnick
Copy link
Contributor Author

Thanks for the review.

I've been thinking about this as a more general pattern to drive service worker adoption (and one that isn't specific to shed) in https://github.com/jeffposnick/gulp-sw-precache. I'm going to solicit some public feedback and brainstorm a bit there, so while I will address this feedback and merge, what gets built in the open there might end up being used here.

@jeffposnick
Copy link
Contributor Author

So I've piled the GA error tracking into this PR, closing #77, and call the same error tracker helper manually if the service worker registration rejects.

@ebidel
Copy link
Contributor

ebidel commented Dec 31, 2014

LGTM. Needs a rebase.

@jeffposnick
Copy link
Contributor Author

Having spent more time experimenting with https://github.com/jeffposnick/gulp-sw-precache, I think it's a better approach than what I initially implemented in this PR, and now I don't think it's worth merging this in. Sorry for the wasted review effort.

Look for a fresh PR based on the code from https://github.com/jeffposnick/gulp-sw-precache

@jeffposnick jeffposnick closed this Jan 5, 2015
@jeffposnick jeffposnick deleted the configure-shed-via-gulp branch January 5, 2015 17:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants