local icons
Summary: Currently icons were always fetched remotely. We used a service worker to prefetch and cache some icons, that were critical to the UI. In this diff, we are bundling icons at build time, with the app. In utils/icons.js we still specfify the list of icons which should be bundled. These are downloaded as part of the build step and bundled with the app. We are downloading the icons in 1x and 2x (the two most common pixel densities). Reviewed By: jknoxville Differential Revision: D16620764 fbshipit-source-id: 965a7793ad1f08aebb292606add00218429cdaf4
This commit is contained in:
committed by
Facebook Github Bot
parent
1717fba410
commit
16e913a819
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
const CACHE_NAME = 'v1';
|
||||
|
||||
self.addEventListener('message', e => {
|
||||
if (e.data.precachedIcons) {
|
||||
caches.open(CACHE_NAME).then(cache => cache.addAll(e.data.precachedIcons));
|
||||
}
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function(event) {
|
||||
if (event.request.url.startsWith('https://external.xx.fbcdn.net/assets/')) {
|
||||
event.respondWith(
|
||||
// Cache falling back to the network
|
||||
caches.match(event.request).then(cacheResponse => {
|
||||
return (
|
||||
cacheResponse ||
|
||||
fetch(event.request).then(response => {
|
||||
const clone = response.clone();
|
||||
// write to cache
|
||||
caches
|
||||
.open(CACHE_NAME)
|
||||
.then(cache => cache.put(event.request, clone));
|
||||
return response;
|
||||
})
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user