question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom template or extension point?

See original GitHub issue

Hi! Thank you for this plugin, really useful and works well.

I would like to hook into the service worker code (I’d like to have custom logic in the fetch listener), and I was wondering if there was any way to hook into it right now?

Thanks, William

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
NekRcommented, Mar 29, 2016

Hi @willdurand,

Yes, you can have custom entry file for SW where you can handle fetch events as you want, but you cannot override behavior for assets listed in caches option. i.e. if you do some API request and want to handle them in SW, just set ServiceWorker.entry option to some JS file, like this:

var OfflinePlugin = require('offline-plugin');

module.exports = {
  // ...

  plugins: [
    // ... other plugins

    new OfflinePlugin({
      // All options are optional
      caches: 'all',
      scope: '/',
      updateStrategy: 'all',
      version: 'v1',

      ServiceWorker: {
        output: 'sw.js',
        entry: 'sw-handler.js'
      },

      AppCache: {
        directory: 'appcache/'
      }
    })
  ]
  // ...
}

and in sw-handler.js:

self.addEventListener('fetch', () => {
  // ...
});

Is it what you wanted?

0reactions
NekRcommented, Jun 2, 2016

Tracking cache mapping issue here now: https://github.com/NekR/offline-plugin/issues/59 Not sure about custom templates though, it reduces whole point of this plugin then since it’s an internal thing which depends on particular version of the plugin. I guess just forking plugin and adopt template for your app is fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating and adding a scripted extension point
When developing an application, create scripted extension points and add them to the script includes in the application code.
Read more >
Extension Points in a Storefront Page - Salesforce Help
This extension point is also known as the core template . ... To insert custom content here, use a Visualforce page include.
Read more >
Creating custom extension points for Mac apps with ExtensionKit
To create a target for a custom extension point, you can pick the "Generic Extension" template from Xcode's new target dialog. Generic Extension ......
Read more >
Extension points - Shopify.dev
Each extension point is triggered by a different merchant action, receives different data, and is responsible for handling a distinct part of the...
Read more >
Creating an extension point - Client-side Extensions
Extension points allow you to provide a safe place for other developers to extend your UI with their own features. An extension point...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found