Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/cache all images #880

Merged
merged 2 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ module.exports = function(webpackEnv) {
// NOTE 2020-01-14 CC - Add support to cache firebase storage and map tiles
runtimeCaching: [
{
urlPattern: /.*\.(?:png|gif|jpg|jpeg|webp|svg).*/gi,
handler: 'cacheFirst',
urlPattern: new RegExp(/.*\.(?:png|gif|jpg|jpeg|webp|svg).*/gi),
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'oa-images',
fetchOptions: {
Expand All @@ -574,20 +574,44 @@ module.exports = function(webpackEnv) {
backgroundSync: {
name: 'oa-images-background',
options: {
maxRetentionTime: 60 * 24,
maxRetentionTime: 60 * 60 * 24,
},
},
expiration: {
maxAgeSeconds: 60 * 24 * 7 * 30,
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 1000,
},
matchOptions: {
ignoreSearch: true,
},
},
},
{
urlPattern: new RegExp(
'^https://firebasestorage\\.googleapis\\.com/',
),
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'oa-other',
fetchOptions: {
credentials: 'same-origin',
mode: 'cors',
},
matchOptions: {
ignoreSearch: true,
},
},
},
{
urlPattern: new RegExp('^https://firestore\\.googleapis\\.com/'),
handler: 'NetworkOnly',
},
],
// end update 2020-01-14
exclude: [/\.map$/, /asset-manifest\.json$/],
importWorkboxFrom: 'cdn',
navigateFallback: publicUrl + '/index.html',
navigateFallbackWhitelist: [/^(?!\/__)/],
navigateFallbackBlacklist: [
// Exclude URLs starting with /_, as they're likely an API call
new RegExp('^/_'),
Expand Down
24 changes: 24 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
}
]
}
],
"headers": [
{
"source": "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
"headers": [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
}
]
},
{
"source": "**/*.@(jpg|jpeg|gif|png)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=604800, s-maxage=3600"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
}
]
}
]
},
"functions": {
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"analyze": "npm run build -- --stats & npx webpack-bundle-analyzer ./build/bundle-stats.json",
"prod:serve": "npm run prod:copy && npm run build && npm run prod:restore && firebase serve",
"prod:copy": "cp .env .env-default && cp ./.env-prod ./.env",
"prod:restore": "cp .env-default .env && rm .env-default",
"start:ci": "cross-env SITE_VARIANT=test-ci BROWSER=none PORT=3456 npm run start",
"cy:run": "cross-env TZ='Europe/London' cypress run",
"cy:open": "cross-env TZ='Europe/London' npx cypress open",
Expand Down Expand Up @@ -189,7 +186,7 @@
"webpack": "4.28.3",
"webpack-dev-server": "3.1.14",
"webpack-manifest-plugin": "2.0.4",
"workbox-webpack-plugin": "3.6.3"
"workbox-webpack-plugin": "4.3.1"
},
"resolutions": {
"@types/react": "16.8.4"
Expand Down
Loading