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

[DO NOT MERGE] Service workers #2

Closed
wants to merge 1 commit into from
Closed

Conversation

rlr
Copy link

@rlr rlr commented Dec 17, 2015

f? @marcoscaceres @k88hudson

I tried the approach of not having to list out all the files to be cached so that a list doesn't have to be maintained. But I suspect this might only cache the assets on the second loading of the page and not the initial load. I haven't proven that yet though.


// NOTE: If we will always serve from a static path (as opposed to a dynamic
// path like /%VERSION%/%CHANNEL%/%LOCALE%/), we can do this below
// instead of the more involved fetch handler below.
Copy link
Author

Choose a reason for hiding this comment

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

I was under the impression that the full path needed to be specified here. If we can do paths like ./ instead, then this is more feasible.

@rlr
Copy link
Author

rlr commented Dec 17, 2015

I meant to say f? not r?

@rlr
Copy link
Author

rlr commented Dec 18, 2015

We discussed in IRC:

5:15 PM <marcosc> so, looks like you are remaking the same boo boos we made in the current version of SW :) Don't worry, everyone does this :)
5:16 PM <r1cky> ok... i just followed the cookbooks haha
5:16 PM <marcosc> yeah, the cookbooks are wrong :(
5:16 PM <marcosc> don't use .addAll(), it's broken
5:16 PM <r1cky> whats wrong with it?
5:16 PM <r1cky> i didnt really use addAll
5:16 PM <marcosc> it caches anything it gets back, including 404
5:16 PM <r1cky> i am sure a bunch of edge cases tho
5:16 PM <marcosc> and 500 :)
5:16 PM <r1cky> oh indidnt do that
5:17 PM <marcosc> yeah, its fucked
5:17 PM <r1cky> i ended up caching manually
5:17 PM <marcosc> also, don't ever go to the cache first 
5:17 PM <marcosc> always hit the network first 
5:17 PM <marcosc> so:
5:18 PM <r1cky> ah. that can be fixed
5:18 PM <marcosc> .addEventListener("fetch", (e)=>{ fethc(e.request).catch(getFromCache(ev.request))})
5:18 PM — r1cky nods
5:18 PM <marcosc> we also did it backwards 
5:19 PM <r1cky> but that makes it slower
5:19 PM <r1cky> hitting network every time
5:19 PM <marcosc> it doesn't, because you are hitting the HTTP cache ;)
5:19 PM <marcosc> r1cky: again, I thought exactly the same thing
5:19 PM <marcosc> but the assumption is wrong 
5:19 PM <r1cky> oh ok. i wasnt sure if that kicked in too
5:19 PM <r1cky> nice
5:20 PM <marcosc> yeah, it's f'ing bs and all the cookbooks have it wrong 
5:20 PM <r1cky> as long as cache headers are set nice
5:20 PM <marcosc> exactly 
5:20 PM <marcosc> but we have those set correctly, so don't worry 
5:20 PM <marcosc> (or we will)
5:20 PM <r1cky> but i am happy to have gone through the exercise
5:20 PM <marcosc> r1cky: so, in theory, our SW code should be about 30-50 lines of code 
5:20 PM <r1cky> learned a little
5:21 PM <marcosc> if it's more than that, we've f'ed somethign up
5:21 PM <marcosc> r1cky: see also: bin/generate-offline-files.js
5:21 PM <r1cky> ok
5:21 PM <marcosc> that gives you the list of files we need to cache as a JSON string
5:23 PM <marcosc> seriously tho, r1cky. If you get over ~50 lines of code, ping me. It means something might be wrong. 
5:24 PM <r1cky> marcosc: yeah... you have a bunch of code in lib/cachetasks... is that needed or is it a shim or?
5:24 PM <r1cky> it covers a bunch more stuff
5:25 PM <marcosc> we might be able to use a little bit of that, but after talking to people in orlando, we don't need most of that
5:25 PM <marcosc> this is probably the best example of how to do things correctly:
5:25 PM <marcosc> https://github.com/wanderview/wanderview.github.com/blob/source/source/sw.js
5:26 PM <marcosc> (Ben Kelly implemented SW in Gecko, so I trust him over anyone else)
5:26 PM <marcosc> He also reviewed all our stuff and said we were doing it all wrong :)
5:26 PM <marcosc> we basically just want his "networkFirst"
5:27 PM <marcosc> r1cky: see also, he filed: https://github.com/mozilla/remote-newtab/issues/151
5:59 PM <r1cky> marcosc: awesome. thanks!!
6:11 PM <marcosc> r1cky: np
6:12 PM <marcosc> r1cky: give a shout if you have any questions, etc. Remember, we've done the SW thing about 3/4 times now, so we've seen most of the pitfalls
6:16 PM — r1cky nods

Closing this one out.

@rlr rlr closed this Dec 18, 2015
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.

1 participant