Menu

#2864 There is no way to set `matchOptions` for `ExpirationPlugin` in generateSW

closed
nobody
None
2021-06-17
2021-06-12
Anonymous
No

Originally created by: cawa-93

Library Affected:
workbox-build, generateSW

Browser & Platform:
"all browsers"

Issue or Feature Request Description:
There is no way to set matchOptions for ExpirationPlugin.

I can only specify these options at a higher level:

{
  runtimeCaching: [
    {
      urlPattern: /^https:\/\/.../,
      handler: 'CacheFirst',
      options: {
        cacheName: 'search-results',
        expiration: {
          maxAgeSeconds: 1,
        },
        matchOptions: {
          ignoreVary: true,
        },
      },
    },
  ]
}

But it will generate the following SW:

  workbox.registerRoute(/^https:\/\/.../, new workbox.CacheFirst({
    "cacheName": "search-results",
    "matchOptions": {
      "ignoreVary": true
    },
    plugins: [new workbox.ExpirationPlugin({
      maxAgeSeconds: 1,
      purgeOnQuotaError: true
    })]
  }), 'GET')

Note that matchOptions no are passed to the ExpirationPlugin. Expected result:

  workbox.registerRoute(/^https:\/\/.../, new workbox.CacheFirst({
    "cacheName": "search-results",
    "matchOptions": {
      "ignoreVary": true
    },
    plugins: [new workbox.ExpirationPlugin({
      maxAgeSeconds: 1,
      purgeOnQuotaError: true,
      "matchOptions": {
        "ignoreVary": true
      },
    })]
  }), 'GET')

If I try to pass these options down:

{
  runtimeCaching: [
    {
      urlPattern: /^https:\/\/.../,
      handler: 'CacheFirst',
      options: {
        cacheName: 'search-results',
        expiration: {
          maxAgeSeconds: 1,
          matchOptions: {
            ignoreVary: true,
          },
        },
        matchOptions: {
          ignoreVary: true,
        },
      },
    },
  ]
}

I will get an error:

ValidationError: "runtimeCaching[0].options.expiration.matchOptions" is not allowed

Related

Tickets: #2865

Discussion

  • Anonymous

    Anonymous - 2021-06-17

    Originally posted by: jeffposnick

    I just tested locally and confirmed that this should be resolved with [#2865].

     

    Related

    Tickets: #2865

  • Anonymous

    Anonymous - 2021-06-17

    Ticket changed by: jeffposnick

    • status: open --> closed
     

Log in to post a comment.