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.

feat: serviceworker

See original GitHub issue

Clear and concise description of the problem

With vite 2.8 we got better worker support with a custom build pipeline.

I propose the same for serviceworker so the following should be transformed:

navigator.serviceWorker.register(new URL('./sw.js', import.meta.url), {/**/})

Suggested solution

This could be a copy of the current worker implementation with the difference that service worker can’t be modules so it allways has to get compiled to an iife. This is also true while in development.

So options should be something like:

export declare interface UserConfig {
   //...
    /**
     * ServiceWorker bundle options
     */
     serviceWorker?: {
        /**
         * Vite plugins that apply to serviceWorker bundle
         */
        plugins?: (PluginOption | PluginOption[])[];
        /**
         * Rollup options to build worker bundle
         */
        rollupOptions?: Omit<RollupOptions, 'plugins' | 'input' | 'onwarn' | 'preserveEntrySignatures'>;
        /**
        * Filename of ServiceWorker in bundle as this should NEVER change
        * @default sw.js
        */
        filename?: string
    };
}

This has some open questions:

  1. What happens when using multiple serviceWorker (with different scope) [how determan filename]

Alternative

No response

Additional context

The same might be usable for Worklets. (Audio, Paint, Animation, Layout)

Validations

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mathe42commented, Apr 22, 2022

I want full control over the SW so not what I need…

1reaction
rockwotjcommented, Jun 20, 2022

This could be a copy of the current worker implementation with the difference that service worker can’t be modules so it allways has to get compiled to an iife. This is also true while in development.

That isn’t true, it can be modules if you use the right option.

https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service Workers | Can I use... Support tables for ... - CanIUse
Service Workers. - CR. Method that enables applications to take advantage of persistent background processing, including hooks to enable bootstrapping of ...
Read more >
API Simulator feat. Service Worker - Paul Bakaus' blog
API Simulator allows you to setup any number of static routes (URLs) on the host it runs on, allowing you to test a...
Read more >
Removing buggy service workers - Chrome Developers
How to fix a service worker that is causing problems. ... Accomplishing this feat depends on the web server and backend stack used, ......
Read more >
Service Worker API - MDN Web Docs
Service workers essentially act as proxy servers that sit between web applications, the browser, and the network (when available).
Read more >
UHS FOOD SERVICE WORKER (FT Varied) Summerlin ...
The average salary for FOOD SERVICE WORKER (FT Varied) Summerlin Hospital at companies like UHS in the United States is $37402 as of...
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