bmeurer / jekyll-workbox-plugin

👨‍🔧Jekyll integration with Google Workbox to create Service Worker automatically.
MIT License
14 stars 5 forks source link

Generates ton of duplicate precacheAndRoute configuration entries when I try to configure wildcard precache_glob_patterns #5

Open MrCsabaToth opened 3 years ago

MrCsabaToth commented 3 years ago

When I have only some simple aliases then it's OK: My sw.js:

// AMP
importScripts('https://cdn.ampproject.org/sw/amp-sw.js');
AMP_SW.init();

// set names for both precache & runtime cache
workbox.core.setCacheNameDetails({
    prefix: 'csaba.page',
    suffix: 'v1.6.5',
    precache: 'precache',
    runtime: 'runtime-cache'
});

// let Service Worker take control of pages ASAP
workbox.skipWaiting();
workbox.clientsClaim();

// default to `networkFirst` strategy
workbox.routing.setDefaultHandler(workbox.strategies.networkFirst());

// let Workbox handle our precache list
// NOTE: This will be populated by jekyll-workbox-plugin.
workbox.precaching.precacheAndRoute([]);

My _config.yaml:

workbox:
  sw_src_filepath: sw.js
  sw_dest_filename: sw.js
  precache_recent_posts_num: 20
  precache_glob_patterns:
    - "index.html":
      - index/
    - "about.html":
      - about/
    - "blog/index.html":
      - blog/
    - "blog/2/index.html":
      - blog/2/
    - "blog/3/index.html":
      - blog/3/
    - "blog/4/index.html":
      - blog/4/

Generated sw.js:

// let Workbox handle our precache list
// NOTE: This will be populated by jekyll-workbox-plugin.
workbox.precaching.precacheAndRoute([{"url":"/index/","revision":"5f680fc54b574f7d9af1abe246681337"},{"url":"/about/","revision":"669063b59099821fa40dbae3d92de078"},{"url":"/blog/","revision":"e42e0016dd1d242efa7370412e04b461"},{"url":"/blog/2/","revision":"058e7125adafb062132c8381c76133f5"},{"url":"/blog/3/","revision":"5bc7f1499c1df52f5f902846c9d65939"},{"url":"/blog/4/","revision":"1f93ec821e310fd127a305eb5aae69bd"},{"url":"/blog/ios-and-eqipment-support.html","revision":"359d222e8d40a1763bf1fe8ab2083bf5"},{"url":"/blog/release-only-bugs.html","revision":"81955b6a7f6b7aaa7ee73bc8b55171bf"},{"url":"/blog/schwinn-ic4-ic8-bowflex-c6-support.html","revision":"3e2c0acf3fc34f24c68ca83c2bd9a090"},{"url":"/blog/track-my-indoor-exercise.html","revision":"61cec960127ff599b8da6bfdef24a36a"},{"url":"/blog/flutter-deal-o-round.html","revision":"7cfdd2a758437724f23b7d1dd2bfc35b"},{"url":"/blog/playn-deal-o-round.html","revision":"e8e5525d05f9fbd4956f5b048f226077"},{"url":"/blog/github-profile-readme.html","revision":"67cbaf71e03efdf38c5ddbdd655023f5"},{"url":"/blog/jetpack-security-shared-preferences.html","revision":"86ae97bdf3392987ba29b6c9fbdfecf5"},{"url":"/blog/ar-physics-progress.html","revision":"7b4ceeab3c65eb67f14bec368b9b55cb"},{"url":"/blog/sceneform-ar-physics.html","revision":"2e1087e84ca0aa20093035b61dcf7f30"},{"url":"/blog/sceneform-breaking-change.html","revision":"9da092381ccdf808082a3b418a85832d"},{"url":"/blog/diy-gps-tracker.html","revision":"3ea44c579283a1212a8c3a860c89aed8"},{"url":"/blog/amp-google-custom-search-engine.html","revision":"dd526a1f0488e86841c29d3015cabadd"},{"url":"/blog/amp-site-tuning.html","revision":"1bb66b649db16ee5ed0e58d607a3d91b"},{"url":"/blog/amp-site-improvements.html","revision":"d343a184ed022a393327fe20bbb69d80"},{"url":"/blog/amp-version-measurements.html","revision":"97af498eb7ccf15a264569ed7eba1df3"},{"url":"/blog/the-website-uses-amp.html","revision":"cf4608395375fc1f6aae225c5c7c6786"},{"url":"/blog/wearos-watch-faces.html","revision":"8e5ca00346fec658708512accbee031f"},{"url":"/blog/flutter-clock-follow-up.html","revision":"4455f572f8d0264a660bd29845c858bd"},{"url":"/blog/devfest-on-demand.html","revision":"48c0fc7ddc32b0eec0ff5b1c08d33dd6"}]);

So far so good. When I add - "{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}" to the precache_glob_patterns because I want to cache images as well (besides the default), then the code generator duplicates that pattern gazillions of times, and a Lighthouse test brings the situation to the point that the service worker layer errors out and results in Uncaught add-to-cache-list-conflicting-entries: Two of the entries passed to 'workbox-precaching.PrecacheController.addToCacheList()' had matching URLs but different revision details. This means workbox-precaching is unable to determine cache the asset correctly. Please remove one of the entries.

workbox:
  sw_src_filepath: sw.js
  sw_dest_filename: sw.js
  precache_recent_posts_num: 20
  precache_glob_patterns:
    - "{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}"
    - "index.html":
      - index/
    - "about.html":
      - about/
    - "blog/index.html":
      - blog/
    - "blog/2/index.html":
      - blog/2/
    - "blog/3/index.html":
      - blog/3/
    - "blog/4/index.html":
      - blog/4/

Generated sw.js:

// let Workbox handle our precache list
// NOTE: This will be populated by jekyll-workbox-plugin.
workbox.precaching.precacheAndRoute([{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"96559ffb5be917f1ce9f748bf4f34732"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"329ae1c377b1fb667f5be6abd50327fc"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"806854d4422d0bd79e0f8c87c329a568"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"8c608256fb0273e3a36e6b603f71f213"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"b00849e00f4c2331cddd8ffb44a6720b"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"adcde98f1d584de52060ad7b16373da3"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"87284894879f5b1c229cb49c8ff6decc"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"60fa3c0614b8fb2f394fa29944c21540"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"babb1eba70ba850a30bf80be9d5214c0"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"1b0e89539560e1f9f7cb9915d6ce0e05"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"e3220c09c2421d8f26994065da564f7f"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"723da9b5a98e62f13e2c6efa78e500f6"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"14ff16b9475d3a1b21ca8150fcdb559f"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"bbb2f5f267a3867c3d8978f05f2e7451"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"2d827598629898fbb4046f502201b702"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"2ce2f0390e1f8ef1bfe0378520aca87e"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"d63e4a11757c26bfe2f7d48708f2a53e"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"ac41e3645e53350aece2e2c7e3de0987"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"c60033c5eb776c2f04f884b29a04f738"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"59f020511712a6e8edd7c6a8d5d72c69"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"a65e1a9ad9d72129464b4e1a6a935634"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"c91bc1d7e95203fa2b499976fcfcaa14"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"80b497d4bd7f2c2456379eca990daad2"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"e04b13a9219c3cf706f7bd33946f4d2d"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"a666f2f46666e24e0b08204331db6cad"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"6a8bf56f791ca1723cefbc5428c11fff"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"a0c95d6973024512b531ec5bc8b3c009"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"303d5c793efda786c77612660832c59c"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"b01d8077c04c7ea22ed1cd1b7af640aa"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"c865c22c5280680ee9c0a8838a837330"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"f9d994b0871c447c63c93d514490ba10"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"3657d17166112bdea31556e090d7886d"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"adf1e4fd2438c9f815d0b675885596f8"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"05bdca8d4de7f0e9d8ed3f260dfd98a1"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"0398ea96edfb70751cdebc12757644c6"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"6e61ab32a4867a939e7b6c97b0d12bd1"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"4197c2f3c3e720c67d8d1e218556d125"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"e06faf6972cbe37000b5e50a2c4d0fe2"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"819defc0bee01e53a741390c1a883c59"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"23627b5064765bd4a6dba08bc7fcd0b2"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"0fa3b89c1bd550462f49cca863894927"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"1a261b32907e99c3b79ddc2b60803715"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"fcd230a57a0dc28116442b61c03440d3"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"c3461315c753fd4dd4ae235ecc561d08"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"516dbc19bfb36bff6ede82be89987e59"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"fcdbeb8f22b9134ef325078bf37c6c25"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"2897aba54b39ebb16c72f5490119b5c3"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"8079fa5634579ace3bd3da91c50c2d5d"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"d05433403275a88ef536b1b52661619a"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"0a94621d6ecbe436629c0187e77c5b90"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"6d7c4540725d95ab47d213b1c14a50b0"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"9ff9e582a79a3e3129fd094d269eb51e"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"7922d05a120cd8f2f3fc7eb7ac1f98c2"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"6ea85a8fc3fd2a5026103f6e70ffa2f8"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"b88ebdaf6d027d9ed366bbaef42bf064"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"17e8fcc5a0621f81d30ec6110155d150"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"d9bb30260c877cb23c08409ece5e16cb"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"cc281d30207be714a5ebcf5c56ca35e0"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"0fa3b89c1bd550462f49cca863894927"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"fb5fa6d14753239d011af2f0c2830c06"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"3961fee361a994e635abb5bad1e191d4"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"0a80646ae204a4372e77dd8745172e5d"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"778ddb1ff241cb687f86c698ceaffd49"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"b5da287026eac5901e0cffa458eb3bb0"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"da100c27d648253e48cdf8a3665a1804"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"95540ede4803fdcd5a3e45760bded7ac"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"34d5749fe92211606b7c93d3e7c3b454"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"156a4865f1d7920a19aa05353f553644"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"b48f814ffe5d687b1f803da4accd4fbf"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"6997be04f2c4b502bc76039afdcf049c"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"8d3101554b4816f330ace8e8789d2033"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"e1c355905a5947066032e430bfb759e4"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"048b88fe333a14a46021b3505941f317"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"834a9798698e79878557cf68731a21fb"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"8e062d6167dfe7e738edb0cb60a42897"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"9da40006e78228bcb7597685db81f1cc"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"261396d1b9c27a5877079d7896933a26"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"e3226e2fc0620e9a65940c904011f265"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"267b6be4aafad53925e7ffeb92b5e4dc"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"61d3d1646f5d4e45d4031e45fa329ccd"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"00c599d373a66d1e3f8cb3b17a169188"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"0a2ea92e6bae6ef3cfe14fffe7af065f"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"3e8c1bec883e8d78448dccec1271ca5c"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"3ecb97dddfd87d1dc1f7121cc71576e4"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"eddea078c0695d86417106ac03bd055a"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"4cec288c7cb8b59bd51b9fdb6fd7a80b"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"de3c53ddfd7120345fd482531aa8d5ed"},{"url":"/{fonts,images}/**/*.{js,css,svg,ttf,woff,jpg,png,webp}","revision":"8f9e3ec42849ce093d3d12227b05716b"},{"url":"/","revision":"9f75b8e5f89b60e28632d30664937ef8"},{"url":"/index/","revision":"9f75b8e5f89b60e28632d30664937ef8"},{"url":"/about/","revision":"e532883f09b52e551fd91d0b10508f58"},{"url":"/blog/","revision":"d79f920905bb2e048a78173010af76c8"},{"url":"/blog/2/","revision":"d6cbc0c9f9ab9865a569f98f5fab2fc3"},{"url":"/blog/3/","revision":"ebd0faedf8fb75775873657e531e9aac"},{"url":"/blog/4/","revision":"d835a789a6ec9ccda72dfc68caa26fb2"},{"url":"/blog/ios-and-eqipment-support.html","revision":"359d222e8d40a1763bf1fe8ab2083bf5"},{"url":"/blog/release-only-bugs.html","revision":"81955b6a7f6b7aaa7ee73bc8b55171bf"},{"url":"/blog/schwinn-ic4-ic8-bowflex-c6-support.html","revision":"3e2c0acf3fc34f24c68ca83c2bd9a090"},{"url":"/blog/track-my-indoor-exercise.html","revision":"61cec960127ff599b8da6bfdef24a36a"},{"url":"/blog/flutter-deal-o-round.html","revision":"7cfdd2a758437724f23b7d1dd2bfc35b"},{"url":"/blog/playn-deal-o-round.html","revision":"e8e5525d05f9fbd4956f5b048f226077"},{"url":"/blog/github-profile-readme.html","revision":"67cbaf71e03efdf38c5ddbdd655023f5"},{"url":"/blog/jetpack-security-shared-preferences.html","revision":"86ae97bdf3392987ba29b6c9fbdfecf5"},{"url":"/blog/ar-physics-progress.html","revision":"7b4ceeab3c65eb67f14bec368b9b55cb"},{"url":"/blog/sceneform-ar-physics.html","revision":"2e1087e84ca0aa20093035b61dcf7f30"},{"url":"/blog/sceneform-breaking-change.html","revision":"9da092381ccdf808082a3b418a85832d"},{"url":"/blog/diy-gps-tracker.html","revision":"3ea44c579283a1212a8c3a860c89aed8"},{"url":"/blog/amp-google-custom-search-engine.html","revision":"dd526a1f0488e86841c29d3015cabadd"},{"url":"/blog/amp-site-tuning.html","revision":"1bb66b649db16ee5ed0e58d607a3d91b"},{"url":"/blog/amp-site-improvements.html","revision":"d343a184ed022a393327fe20bbb69d80"},{"url":"/blog/amp-version-measurements.html","revision":"97af498eb7ccf15a264569ed7eba1df3"},{"url":"/blog/the-website-uses-amp.html","revision":"cf4608395375fc1f6aae225c5c7c6786"},{"url":"/blog/wearos-watch-faces.html","revision":"8e5ca00346fec658708512accbee031f"},{"url":"/blog/flutter-clock-follow-up.html","revision":"4455f572f8d0264a660bd29845c858bd"},{"url":"/blog/devfest-on-demand.html","revision":"48c0fc7ddc32b0eec0ff5b1c08d33dd6"}]);
MrCsabaToth commented 3 years ago

In the faulty sw.js generated file the wildcard pattern repeats ~85 times! Hence we get the add-to-cache-list-conflicting-entries

bmeurer commented 3 years ago

Yeah, the code is pretty naive unfortunately. I'm not using Jekyll and this plugin currently, and don't really have time to look into it. But feel free to send a PR.

MrCsabaToth commented 3 years ago

Yeah, the code is pretty naive unfortunately. I'm not using Jekyll and this plugin currently, and don't really have time to look into it. But feel free to send a PR.

I'll need to learn Ruby for that. I'll peek into https://github.com/souldanger/jekyll-pwa-workbox/ maybe I can figure out something