Service Worker


bit Bswup has a lot of options available in the service worker file to configure its behavior.

Bswup Service Worker
A sample of all configuration available inside of the service worker file is shown here:
self.assetsInclude = [/\data.db$/];
self.assetsExclude = [/\.scp\.css$/, /weather\.json$/];
self.defaultUrl = '/';
self.prohibitedUrls = [/\/admin\//];
self.serverHandledUrls = [/\/api\//];
self.serverRenderedUrls = [/\/privacy$/];
self.externalAssets = [
    {
        "url": "/"
    },
    {
        "url": "https://www.googletagmanager.com/gtag/js?id=G-G123456789"
    }
];
self.assetsUrl = '/service-worker-assets.js';
self.noPrerenderQuery = 'no-prerender=true';
self.caseInsensitiveUrl = true;
self.ignoreDefaultInclude = true;
self.ignoreDefaultExclude = true;
self.isPassive = true;
self.disablePassiveFirstBoot = true;
self.enableIntegrityCheck = true;
self.enableDiagnostics = true;
self.enableFetchDiagnostics = true;

self.importScripts('_content/Bit.Bswup/bit-bswup.sw.js');
Note: The most important line here is the last line which is the only mandatory config in this file that imports the Bswup service-worker file:
self.importScripts('_content/Bit.Bswup/bit-bswup.sw.js');
These available configurations are explained below:

assetsInclude: The list of file names from the assets list to include when the Bswup tries to store them in the cache storage (regex supported).

assetsExclude: The list of file names from the assets list to exclude when the Bswup tries to store them in the cache storage (regex supported).

externalAssets: The list of external assets to cache that are not included in the auto-generated assets file. For example, if you're not using index.html (like _host.cshtml), then you should add { "url": "/" }.

defaultUrl: The default page URL. Use / when using _Host.cshtml.

assetsUrl: The file path of the service-worker assets file generated at compile time (the default file name is service-worker-assets.js).

prohibitedUrls: The list of file names that should not be accessed (regex supported).

caseInsensitiveUrl: Enables the case insensitivity in the URL checking of the cache process.

serverHandledUrls: The list of URLs that do not enter the service-worker offline process and will be handled only by server (regex supported). such as /api, /swagger, ...

serverRenderedUrls: The list of URLs that should be rendered by the server and not client while navigating (regex supported). such as /about.html, /privacy, ...

noPrerenderQuery: The query string attached to the default document request to disable the prerendering from the server so an unwanted prerendered result not be cached.

ignoreDefaultInclude: Ignores the default asset includes array which is provided by the Bswup itself which is like this:
[/\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/, /\.svg$/, /\.woff2$/, /\.ttf$/, /\.webp$/]
ignoreDefaultExclude: Ignores the default asset excludes array which is provided by the Bswup itself which is like this:
[/^_content\/Bit\.Bswup\/bit-bswup\.sw\.js$/, /^service-worker\.js$/]"
Note: Keep in mind that caching service-worker related files will corrupt the update cycle of the service-worker. Only the browser should handle these files.

isPassive: Enables the Bswup's passive mode. In this mode, the assets won't be cached in advance but rather upon initial request.

disablePassiveFirstBoot: Disables downloading the Blazor's boot files in first time of Passive mode.

enableIntegrityCheck: Enables the default integrity check available in browsers by setting the integrity attribute of the request object created in the service-worker to fetch the assets.

enableDiagnostics: Enables diagnostics by pushing service-worker logs to the browser console.

enableFetchDiagnostics: Enables fetch event diagnostics by pushing service-worker fetch event logs to the browser console.