about summary refs log tree commit diff
path: root/config/webpack
diff options
context:
space:
mode:
authorNolan Lawson <nolan@nolanlawson.com>2017-10-31 04:25:51 -0700
committerEugen Rochko <eugen@zeonfederated.com>2017-10-31 12:25:51 +0100
commit0692991b54c660d1292ff2cea0fa135c952c608e (patch)
treeecdb8406b1ed40ff1a0ba913ce7d24d3004f1d9c /config/webpack
parent6705463ed0776b8d882aa190be081a1049a10531 (diff)
Add ServiceWorker caching for static assets (#5524)
Diffstat (limited to 'config/webpack')
-rw-r--r--config/webpack/production.js32
1 files changed, 31 insertions, 1 deletions
diff --git a/config/webpack/production.js b/config/webpack/production.js
index cd1dd91dc..6de79c811 100644
--- a/config/webpack/production.js
+++ b/config/webpack/production.js
@@ -48,7 +48,37 @@ module.exports = merge(sharedConfig, {
     }),
     new OfflinePlugin({
       publicPath: publicPath, // sw.js must be served from the root to avoid scope issues
-      caches: { }, // do not cache things, we only use it for push notifications for now
+      caches: {
+        main: [':rest:'],
+        additional: [':externals:'],
+        optional: [
+          '**/locale_*.js', // don't fetch every locale; the user only needs one
+          '**/*_polyfills-*.js', // the user may not need polyfills
+          '**/*.woff2', // the user may have system-fonts enabled
+          // images/audio can be cached on-demand
+          '**/*.png',
+          '**/*.jpg',
+          '**/*.jpeg',
+          '**/*.svg',
+          '**/*.mp3',
+          '**/*.ogg',
+        ],
+      },
+      externals: [
+        '/emoji/1f602.svg', // used for emoji picker dropdown
+        '/emoji/sheet.png', // used in emoji-mart
+      ],
+      excludes: [
+        '**/*.gz',
+        '**/*.map',
+        'stats.json',
+        'report.html',
+        // any browser that supports ServiceWorker will support woff2
+        '**/*.eot',
+        '**/*.ttf',
+        '**/*-webfont-*.svg',
+        '**/*.woff',
+      ],
       ServiceWorker: {
         entry: path.join(__dirname, '../../app/javascript/mastodon/service_worker/entry.js'),
         cacheName: 'mastodon',