I see a lot of example code like this: (Slightly shortened version of this Mozilla Doc)
this.addEventListener('install', function(event) {
event.waitUntil(
caches.open('v1').then(function(cache) {
return cache.addAll([
'/sw-test/',
'/sw-test/index.html',
'/sw-test/style.css',
'/sw-test/gallery/',
'/sw-test/gallery/bountyHunters.jpg',
]);
})
);
});
I don't understand why you add both /sw-test/
and /sw-test/index.html
. Seems like either the first folder URL should autoload everything underneath, or, if it doesn't do that, why is it there? Same for /sw-test/gallery/
and /sw-test/gallery/bountyHunters.jpg
.
The docs say "The addAll() method of the Cache interface takes an array of URLs, retrieves them, and adds the resulting response objects to the given cache". Which isn't very helpful.
What I really want to do is cache all the *.html files from a few folders and all the image files (in various formats) from another folder. Listing them one-by-one is fragile (will quickly get out-of-sync), prone to typos, and is just plain silly.
Added Later
After further reading, doesn't seem like wildcards exist, so silly it is. :-) But whats the point of adding a folder like /sw-test/
?