A rewrite of the Raspberry Pi Garage Door Opener using Flask
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. // CREDITS: https://github.com/umluizlima/flask-pwa/blob/master/app/static/sw.js
  2. // File Created by [Check Commits for Name]
  3. console.log('Hello from sw.js');
  4. importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.2.0/workbox-sw.js');
  5. if (workbox) {
  6. console.log(`Yay! Workbox is loaded 🎉`);
  7. workbox.precaching.precacheAndRoute([
  8. {
  9. "url": "/login",
  10. "revision": "1"
  11. }
  12. ]);
  13. workbox.routing.registerRoute(
  14. /\.(?:js|css)$/,
  15. workbox.strategies.staleWhileRevalidate({
  16. cacheName: 'static-resources',
  17. }),
  18. );
  19. workbox.routing.registerRoute(
  20. /\.(?:png|gif|jpg|jpeg|svg)$/,
  21. workbox.strategies.cacheFirst({
  22. cacheName: 'images',
  23. plugins: [
  24. new workbox.expiration.Plugin({
  25. maxEntries: 60,
  26. maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
  27. }),
  28. ],
  29. }),
  30. );
  31. workbox.routing.registerRoute(
  32. new RegExp('https://fonts.(?:googleapis|gstatic).com/(.*)'),
  33. workbox.strategies.cacheFirst({
  34. cacheName: 'googleapis',
  35. plugins: [
  36. new workbox.expiration.Plugin({
  37. maxEntries: 30,
  38. }),
  39. ],
  40. }),
  41. );
  42. } else {
  43. console.log(`Boo! Workbox didn't load 😬`);
  44. }