-
Notifications
You must be signed in to change notification settings - Fork 174
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
fix: precached files are not updated #386
Merged
+33
−2
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c605134
fix: precached files are not updated
kedrzu bd04e0d
refactor: move randomString to utils
pi0 77a4464
refactor: apply default revision in options.js
pi0 ef76211
test: update snapshot
pi0 df107b5
Merge branch 'master' into master
pi0 801ff5c
test: fix revision
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,17 @@ function initWorkbox(workbox, options) { | |
|
||
function precacheAssets(workbox, options) { | ||
if (options.preCaching.length) { | ||
workbox.precaching.precacheAndRoute(options.preCaching, options.cacheOptions) | ||
const cacheOptions = options.cacheOptions || {}; | ||
const precacheList = options.preCaching.map(url => ({ | ||
url: url, | ||
revision: cacheOptions.revision | ||
})) | ||
|
||
workbox.precaching.precacheAndRoute(precacheList, options.cacheOptions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to google: Revision must be passed separately per each precached file and not in options object. |
||
} | ||
} | ||
|
||
|
||
function runtimeCaching(workbox, options) { | ||
for (const entry of options.runtimeCaching) { | ||
const urlPattern = new RegExp(entry.urlPattern) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no revision is set, browser complains about precaching file without revision:
I think that adding some randomized revision as a default would be beneficial.
I tried to get random version from
nuxt
environmental variables, but couldn't find it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to pass
null
instead for revision info of_nuxt/
assets because we always add hash to URL for long-term caching:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, for script assets that's true. But this case is about
.html
files, which do not have any hash in name.Once they are precached, you cannot do anything to update them, other than unregistering and registering service worker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same applies to offline page (
404.html
) and start url for PWA (/?standalone=true
by default).Once they get precached, PWA stops being updated and offline page too.
This is a behavior I observed in my own application - when installed app as a standalone PWA application it refused to be updated even if completely new deploy was made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you are right. But the problem is that generating revision on build-time only works for static generated websites. If response of a SSR page changes, workbox still refuses to update..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If precache would work with
NetworkFirst
, everything would be fine.But from what I've read, it always work as
CacheFirst
.Maybe it's a good idea to disable precaching at all? Or replace it with manually fetching those pages in
sw.js
file and caching them with standardNetworkFirst
cache, instead of depending onworkbox
standard precache?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kedrzu This PR looks good after and partially fixing issue. But indeed, precaching is only
CacheFirst
(GoogleChrome/workbox#1767).I will try to implement new
offlineRoutes
option for (NF or SWR) strategy :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#406