audio_cache_sw.js 822 B

1234567891011121314151617181920
  1. const FILE_NAME = 'https://admin.meemapp.net/notif-order.mp3';
  2. self.addEventListener('fetch', event => {
  3. // Checking if the url matches the audio file.
  4. // This is actually not really needed right now, we could just check if the request is
  5. // cached (for any file) and return it. If you decide to put the response from the network
  6. // fetch into the cache then this check might be valueble to only store the audio files.
  7. if (event.request.url.indexOf(FILE_NAME) === 0) {
  8. console.log('Audio file requested!')
  9. event.respondWith(
  10. caches.match(event.request).then(function(response) {
  11. console.log(Boolean(response) ? 'Serving from cache' : 'Fetching from network');
  12. return response || fetch(event.request);
  13. })
  14. );
  15. } else {
  16. event.respondWith(fetch(event.request));
  17. }
  18. });