Skip to content

Instantly share code, notes, and snippets.

@imsus
Created May 24, 2020 05:35
Show Gist options
  • Save imsus/c7b0cfacebe1c1679911b452c2dc89e4 to your computer and use it in GitHub Desktop.
Save imsus/c7b0cfacebe1c1679911b452c2dc89e4 to your computer and use it in GitHub Desktop.
Workbox configuration for Hugo
module.exports = {
cacheId: "imsus.dev-production",
globDirectory: "./public",
globPatterns: ["**/*.{css,js,eot,ttf,woff,woff2,otf}"],
swDest: "./public/service-worker.js",
modifyURLPrefix: {
"": "/",
},
clientsClaim: true,
skipWaiting: true,
ignoreURLParametersMatching: [/./],
offlineGoogleAnalytics: true,
maximumFileSizeToCacheInBytes: 50 * 1024 * 1024,
runtimeCaching: [
{
urlPattern: /(?:\/)$/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "html",
expiration: {
maxAgeSeconds: 60 * 60 * 24 * 7,
},
},
},
{
urlPattern: /\.(?:png|jpg|jpeg|gif|bmp|webp|svg|ico)$/,
handler: "CacheFirst",
options: {
cacheName: "images",
expiration: {
maxEntries: 1000,
maxAgeSeconds: 60 * 60 * 24 * 365,
},
},
},
{
urlPattern: /\.(?:mp3|wav|m4a)$/,
handler: "CacheFirst",
options: {
cacheName: "audio",
expiration: {
maxEntries: 1000,
maxAgeSeconds: 60 * 60 * 24 * 365,
},
},
},
{
urlPattern: /\.(?:m4v|mpg|avi)$/,
handler: "CacheFirst",
options: {
cacheName: "videos",
expiration: {
maxEntries: 1000,
maxAgeSeconds: 60 * 60 * 24 * 365,
},
},
},
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment