diff --git a/rootfs/etc/nginx/conf.d/default.conf b/rootfs/etc/nginx/conf.d/default.conf index f05c38bd2..30290e3ac 100644 --- a/rootfs/etc/nginx/conf.d/default.conf +++ b/rootfs/etc/nginx/conf.d/default.conf @@ -7,7 +7,13 @@ server { root /usr/share/nginx/html; index index.html index.html; - + + location ~* ^/(images|symbols|ogv)(/.*)*\.(svg|png|jpe?g|gif|webp|ico|js|css|woff2?)$ { + add_header Cache-Control "public, max-age=31536000, immutable" always; + access_log off; + log_not_found off; + } + try_files $uri $uri/ /index.html; set $auth_basic off; diff --git a/sw-precache-config.js b/sw-precache-config.js index 76e749f8d..14e43fa98 100644 --- a/sw-precache-config.js +++ b/sw-precache-config.js @@ -29,11 +29,21 @@ module.exports = { staticFileGlobs: [ 'build/*.html', 'build/manifest.json', - 'build/static/**/!(*map*)', + 'build/static/**/*.*', ...boardImages ], maximumFileSizeToCacheInBytes: 4194304, runtimeCaching: [ + { + urlPattern: /\/static\//, + handler: 'cacheFirst', + options: { + cache: { + name: 'static-assets', + maxEntries: 200 + } + } + }, { urlPattern: /\/symbols\/mulberry/, handler: 'cacheFirst', @@ -62,10 +72,11 @@ module.exports = { } } ], - dontCacheBustUrlsMatching: /\.\w{8}\./, + navigateFallback: '/index.html', + navigateFallbackWhitelist: [/^\/(?!api).*/], + dontCacheBustUrlsMatching: /\.(js|css|json|jpg|jpeg|png|svg|ico)$/, dynamicUrlToDependencies: { '/': ['build/index.html'] }, - navigateFallback: '/', swFilePath: 'build/service-worker.js' };