-
Notifications
You must be signed in to change notification settings - Fork 389
How to cache "/"? #246
Comments
Maintaining 4 different cached copies of the same underlying HTML file—
There's another option in Using both of those options together, (I've suggested using |
@jeffposnick Sorry, but this does not address the issue that I'm having. Let me see if I can clarify: I'm using sw-precache with this configuration: swPrecache: {
swFileName: 'service-worker.js',
directoryIndex: '/',
options: {
stripPrefix: 'priv/static/',
staticFileGlobs: ['priv/static/**/*.*']
}
} My application cache currently looks like this: However, in order to get my app to render in offline mode, one of those entries must be If I manually create a service worker to look like this: self.addEventListener('install', function(e) {
e.waitUntil(
caches
.open('vuechat')
.then(cache => cache.addAll([
'/',
'/service-worker.js',
'/js/app.js',
'/css/app.css',
'/css/components.css',
'/images/vuechat-logo.png',
'/favicon.ico',
'/browserconfig.xml',
'/manifest.json',
'/robots.txt',
'/favicons/android-chrome-144x144.png',
'/favicons/apple-touch-icon.png',
'/favicons/favicon-16x16.png',
'/favicons/favicon-32x32.png',
'/favicons/favicon.ico',
'/favicons/mstile-150x150.png',
'/favicons/safari-pinned-tab.svg',
]))
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches
.match(event.request)
.then(response => response || fetch(event.request))
);
}); I get exactly the behavior that I'm expecting. So, my question is, how do I get sw-precache to include |
Gotcha. What you describe is handled by the You can see an example configuration at https://github.com/GoogleChrome/sw-precache/blob/master/app-shell-demo/gulpfile.babel.js#L127—it uses See also #156 for some discussion around whether "dynamicUrlToDependencies" makes sense as a name, and whether it's surfaced properly in the documentation. |
haha, I was going to complain that I couldn't get it to work, and then realized I didn't have the Working fine now, thanks! |
But what if your dependencies have nested dependencies? In React we use composition a lot, so there's no guarantee that when my top-level component's hash doesn't change the HTML response is the same. |
@janhoogeveen, if we're talking specifically about keeping the App Shell HTML up to date when using React to populate your content, the model that I've seen used successfully is to include just the basic placeholder where the DOM insertion will take place in the App Shell HTML, as in this example: Maybe there are scenarios in which you really need to include the HTML equivalent of your components' DOM encapsulated in your App Shell HTML, in which case yes, you'd have to list all of the files that contribute uniquely to that component's output as part of the If you have more details about why that wouldn't work for your use case, it would help if you could file a new issue explaining what you're running into, and pointing to a sample repo/live deployment. |
Thanks very much for your response @jeffposnick Seems like just loading the template/app shell works fine as is indeed. I kind of forgot that by loading just the shell the JS can fill in everything with the cached JS assets afterwards. Works like a charm in my repo now. |
@jeffposnick how to handle the cdn path ? specify
But that's not what I want ,and the so how to fix this ? |
See my response at goldhand/sw-precache-webpack-plugin#79 (comment) I don't think hosting assets between a CDN and HTML + SW on a different server is a use case that we can easily support. |
Query strings starting with I'm not aware of any way how to configure that in CRA without ejecting so I've just changed the See this SO question for more details. |
What would be the problem with deifining index at runtimeCaching for example like ` |
Most of the guides online will tell you to set of your service worker cache like so (taken from the google airhorn pwa example):
Notice that the first thing being added is
'/'
, which caches the home page. What I can't figure out is how to get sw-precache to include this. I've been able to get it to successfully include every actual static file that I need, but not that open/
.The text was updated successfully, but these errors were encountered: