-
-
Notifications
You must be signed in to change notification settings - Fork 78.8k
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
Pre-cache key assets with Workboxjs. #23533
Conversation
196a5bd
to
11c0af1
Compare
Jekyll builds the md files to html. Please make sure we are not caching useless stuff. |
sw-src.js
Outdated
@@ -0,0 +1,7 @@ | |||
'use strict'; |
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.
Why do we need this file? Can't you do what you want in sw.js?
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.
We can, but this serves as a template to generate the main sw.js file
@@ -1 +1,156 @@ | |||
// empty for now |
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 this file is generated, then it should be removed now.
And output the generated sw.js in _gh_pages folder.
11c0af1
to
7c2b2eb
Compare
Then see my comment about the dist folder.
…On Aug 18, 2017 03:06, "Michael" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In sw-src.js
<#23533 (comment)>:
> @@ -0,0 +1,7 @@
+'use strict';
We can, but this serves as a template to generate the main sw.js file
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#23533 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAVVtb-dJDwr7rj1VlHsNshVrC_yvTjhks5sZNWMgaJpZM4O65qg>
.
|
7c2b2eb
to
1590326
Compare
Should be all good now? |
build/workbox.config.json
Outdated
"assets/**/*.{js,html,svg,png,css,jpg,ico}", | ||
"dist/**/*.{js,html,svg,png,css,jpg,ico}" | ||
], | ||
"swSrc": "sw-src.js", |
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.
How about just naming this sw.js
? We output the generated file in the _gh_pages folder so we don't have any conflicts.
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.
makes more sense, will update
sw-src.js
Outdated
@@ -0,0 +1,6 @@ | |||
importScripts('https://unpkg.com/workbox-sw@1.3.0'); |
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.
Why do you use unpkg and not a local devDependency?
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.
that makes more sense actually, working on it.
package.json
Outdated
@@ -52,7 +52,8 @@ | |||
"test": "npm-run-all dist js-test docs", | |||
"watch": "npm-run-all --parallel watch-css watch-js", | |||
"watch-css": "nodemon --ignore js/ --ignore dist/ -e scss -x \"npm run css && npm run css-docs\"", | |||
"watch-js": "nodemon --ignore scss/ --ignore js/dist/ --ignore dist/ -e js -x \"npm run js-compile-plugins\"" | |||
"watch-js": "nodemon --ignore scss/ --ignore js/dist/ --ignore dist/ -e js -x \"npm run js-compile-plugins\"", | |||
"workbox-precache": "workbox-cli inject:manifest --configFile=\"build/workbox.config.json\"" |
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.
We need to hook this script in the other scripts, say docs
. And also rename it to docs-workbox-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.
It fails on travis due to incompatibility with node 4, so I had to remove it from the docs script to pass, but i've put in a pull request to fix it though, so waiting on that for now
@Lyricalz: apart from the previous stuff I commented, you need to update package-lock.json too after you fetch and rebase from v4-dev. |
sw-src.js
Outdated
@@ -0,0 +1,6 @@ | |||
importScripts('https://unpkg.com/workbox-sw@1.3.0'); | |||
|
|||
const VERSION = 1; |
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.
Wouldn't it make sense to use the version from package.json + another variable?
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.
yeah that's a good idea, since this is linked to the docs, are there any vars that are updated whenever the docs are rebuilt?
4b99f70
to
286b5ef
Compare
Made some updates Note: build still hasn't passed on node 4 but once the workbox-team have merged & released i'll update to that version and it should pass then |
286b5ef
to
8c5f98f
Compare
build/workbox.js
Outdated
} | ||
}) | ||
|
||
config.manifestTransforms = [mdToHtml] |
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.
Why do we need workbox to do MD -> HTML?
The _gh_pages folder already has the html files.
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.
see comment below
build/workbox.config.json
Outdated
"globPatterns": [ | ||
"assets/**/*.{js,svg,png,css}", | ||
"dist/**/*.{js,css}", | ||
"docs/**/*.{md,html,css,jpg,js}" |
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.
We shouldn't cache md files.
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.
Also, this seems to generic. You should change the whole config to work against the _gh_pages folder which only has the needed assets and not the src stuff.
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.
Okay so I added a transformer for this as if I specified the _gh_pages folder, workbox will attempt to pre-cache an url like.. http://getbootstrap.com/gh_pages/docs/4.0/, instead of http://getbootstrap.com/docs/4.0/. The transformer basically renames the .md files to their correct .html files but keeps the docs/ structure intact instead of _gh_pages/docs/
build/workbox.config.json
Outdated
"templatedUrls": { | ||
"/": ["_gh_pages/docs/index.html"], | ||
"docs": ["_gh_pages/docs/index.html"], | ||
"docs/4.0/": ["_gh_pages/docs/4.0/index.html"] |
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.
Why do we need this? If we cache the whole _gh_pages folder, doesn't workbox take care of this for us?
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.
So 'templatedUrls' is just a way to redirect urls to their relative sources. Since the docs uses /docs/index instead.html of _gh_pages/docs/index.html and _gh_pages/* doesn't actually exist via 'http://getbootstrap.com/gh_pages/*', we're basically saying get the source contents of _gh_pages/docs/index.html and the cache the contents of it as if you're visiting the url '/'.
build/workbox.js
Outdated
@@ -0,0 +1,28 @@ | |||
'use strict' | |||
|
|||
var fse = require('fs-extra') |
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.
You don't list fs-extra in devDependencies? BTW can't we just use fs
?
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.
Oh, also, you could/should ES6-ify this file.
@Lyricalz : thanks for your patience, we'll get there :) |
8c5f98f
to
b54fbfc
Compare
@XhmikosR actually I wasn't thinking right about the md-html thing, should just go straight to the _gh_pages as you suggested, just updated and moved back to just normal fs instead. I think we've got it now, i've also updated the transformer to just remove the '_gh_pages' in the url |
b54fbfc
to
756ea5a
Compare
933d7f2
to
04bab42
Compare
aa3e86b
to
07dccca
Compare
@XhmikosR I've just rebased and upgraded workbox-build to 2.0.1 which includes your backslash fix, we ready to merge? 😄 |
063d3f9
to
e8c8b76
Compare
@Lyricalz: I rebased the branch, please make sure you don't overwrite my changes. Now, 3 final issues, I promise :)
|
@XhmikosR i've updated 1) to get rid of this error |
86a6c04
to
c1273bf
Compare
The error I was getting must be because the service worker wasn't properly being registered without your last patch :) Now I can navigate the docs offline.
I think we are almost done :) @gauntface: do you have any idea why we get this for the favicons?
I see sw.js has them so something else must be going on. |
|
Also re: |
build/workbox.config.json
Outdated
@@ -1,7 +1,7 @@ | |||
{ | |||
"globDirectory": "./", | |||
"globPatterns": [ | |||
"_gh_pages/**/*.{html,css,js,png,jpg}" | |||
"_gh_pages/**/*.{html,css,js,json,png,jpg}" |
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.
With respect to the favicon issue you're seeing, is it possible to view your current build in Chrome Canary and take a screenshot of what is in Application Panel -> Cache Storage? Favicon issues like this are often due to the asset either not existing in the final build, the globPattern not being sufficient (don't believe this is an issue here) or something else.
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.
6821a78
to
53e448c
Compare
53e448c
to
fa03833
Compare
Thanks to everyone for the help and ofc @Lyricalz for your patience! I'll keep an eye for any regressions or fixes for the favicon issue. |
Awesome! |
Just a cheeky FYI, if you have any further issues, feature requests or feedback for Workbox please raise an issue (thanks for you help fixing the windows bug ;) ). |
@gauntface would you mind reviewing this file please? Would you say that is the recommended way to prompt an update with service workers? |
@Lyricalz: another thing I noticed is that if you visit the homepage, go offline, then the docs page isn't cached. I think is something with the page being redirected. |
@XhmikosR I noticed this too, but that's because the live link is hardcoded in the redirect, rather than the local url. I was thinking about making a PR, to make these links relative, rather than using absolute URLs. When you click documentation it actually goes here: |
@Lyricalz: we use jekyll-redirect-from for the redirects so I'm not sure if it's even possible since I haven't looked at it. If you make a PR please CC me. |
@Lyricalz that looks fine to me. Workbox-sw does provide an alternative way to listen for a broadcast message when assets are updated: https://github.com/GoogleChromeLabs/workbox-microsite/blob/master/src/themes/scripts/sw-controller.js#L18 |
First time attempting to contribute, so bare with me please if i've missed anything or done anything wrong.
But I noticed this was merged ( #23101 ) so in addition, thought it would make sense to pre-cache those main assets.
Also not too sure how it works but I think Jekyll is serving/parsing the markdown doc files dynamically. It would be a cool idea if we could maybe get them to static html files? That way we can have offline support with this too!
Screenshot to show speed difference:
https://snag.gy/KzD0Rv.jpg - throttled slow 3G
https://snag.gy/YHsyzB.jpg - throttled slow 3G w/ workboxjs
Also ran
grunt test
and everything passed fine.