From 9376760fc50d0176c2c00c088f480d8bc04354e4 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 2 Dec 2022 19:50:48 +0100 Subject: [PATCH] updated caching strategy --- frontend/firebase.json | 35 +++++++++-- frontend/webpack/config.prod.js | 106 ++++++++++++++++++++------------ 2 files changed, 99 insertions(+), 42 deletions(-) diff --git a/frontend/firebase.json b/frontend/firebase.json index 6f66a64c9..2f65e5cde 100644 --- a/frontend/firebase.json +++ b/frontend/firebase.json @@ -47,20 +47,47 @@ ] }, { - "source": "**/*.@(jpg|jpeg|gif|png|svg|webp|js|css|eot|otf|ttf|ttc|woff|woff2|font.css|wav|txt)", + "source": "**/*.@(jpg|jpeg|gif|png|svg)", "headers": [ { "key": "Cache-Control", - "value": "max-age=604800" + "value": "max-age=31536000" } ] }, { - "source": "**/*.@(json)", + "source": "**/*.@(eot|otf|ttf|ttc|woff|woff2)", "headers": [ { "key": "Cache-Control", - "value": "max-age=7200" + "value": "max-age=31536000" + } + ] + }, + { + "source": "**/*.@(json|wav|txt|css)", + "headers": [ + { + "key": "Cache-Control", + "value": "max-age=3600" + } + ] + }, + { + "source": "**/*.min.@(js|css)", + "headers": [ + { + "key": "Cache-Control", + "value": "max-age=31536000" + } + ] + }, + { + "source": "**/*.????????.@(js|css)", + "headers": [ + { + "key": "Cache-Control", + "value": "max-age=31536000" } ] }, diff --git a/frontend/webpack/config.prod.js b/frontend/webpack/config.prod.js index 10d017991..44e1d4223 100644 --- a/frontend/webpack/config.prod.js +++ b/frontend/webpack/config.prod.js @@ -82,48 +82,78 @@ const PRODUCTION_CONFIG = { //include the generated css and js files maximumFileSizeToCacheInBytes: 11000000, exclude: [ - /html\/.*\.html/, - /LICENSE\.txt/, - /\.DS_Store/, - /\.map$/, - /^manifest.*\.js$/, - /languages\/.*\.json/, - /quotes\/.*\.json/, - /themes\/.*\.css/, - /challenges\/.*\.txt/, - /sound\/.*\.wav/, - /images\/.*\.(png|jpg)/, - /webfonts\/.+/, + // /html\/.*\.html/, + // /LICENSE\.txt/, + // /\.DS_Store/, + // /\.map$/, + // /^manifest.*\.js$/, + // /languages\/.*\.json/, + // /quotes\/.*\.json/, + // /themes\/.*\.css/, + // /challenges\/.*\.txt/, + // /sound\/.*\.wav/, + // /images\/.*\.(png|jpg)/, + // /webfonts\/.+/, + /./, ], runtimeCaching: [ + // { + // urlPattern: /.+\.(jpg|jpeg|gif|png|svg)/, + // handler: "CacheFirst", + // }, + // { + // urlPattern: /.+\.(eot|otf|ttf|ttc|woff|woff2)/, + // handler: "CacheFirst", + // }, + // // { + // // urlPattern: /.+\.(json|wav|txt|css)/, + // // handler: "NetworkFirst", + // // }, + // { + // urlPattern: /.+\.min\.(js|css)/, + // handler: "CacheFirst", + // }, + // { + // urlPattern: /.+\..{8}\.(js|css)/, + // handler: "CacheFirst", + // }, { - urlPattern: /languages\/.*\.json/, - handler: "StaleWhileRevalidate", - }, - { - urlPattern: /quotes\/.*\.json/, - handler: "StaleWhileRevalidate", - }, - { - urlPattern: /themes\/.*\.css/, - handler: "StaleWhileRevalidate", - }, - { - urlPattern: /challenges\/.*\.txt/, - handler: "StaleWhileRevalidate", - }, - { - urlPattern: /sound\/.*\.wav/, - handler: "StaleWhileRevalidate", - }, - { - urlPattern: /images\/.*\.(png|jpg)/, - handler: "StaleWhileRevalidate", - }, - { - urlPattern: /webfonts\/.+/, - handler: "CacheFirst", + urlPattern: /.+/, + handler: "NetworkFirst", }, + + // { + // urlPattern: /languages\/.*/, + // handler: "StaleWhileRevalidate", + // }, + // { + // urlPattern: /quotes\/.*/, + // handler: "StaleWhileRevalidate", + // }, + // { + // urlPattern: /themes\/.*/, + // handler: "StaleWhileRevalidate", + // }, + // { + // urlPattern: /challenges\/.*/, + // handler: "StaleWhileRevalidate", + // }, + // { + // urlPattern: /layouts\/.*/, + // handler: "StaleWhileRevalidate", + // }, + // { + // urlPattern: /sound\/.*\.wav/, + // handler: "StaleWhileRevalidate", + // }, + // { + // urlPattern: /images\/.*\.(png|jpg)/, + // handler: "StaleWhileRevalidate", + // }, + // { + // urlPattern: /webfonts\/.+/, + // handler: "CacheFirst", + // }, ], }), ],