Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

A customizable and dynamic, yet simple service worker for your website

License

Notifications You must be signed in to change notification settings

falahati/AdvancedServiceWorker

Repository files navigation

AdvancedServiceWorker

A customizable and dynamic, yet simple service worker for your website

Where to get

To download the latest version of this program, take a look at the releases page.

Donation

Donations assist development and are greatly appreciated; also always remember that every coffee counts! :)

--OR--

You can always donate your time by contributing to the project or by introducing it to others.

Simple Usage

<script type="text/javascript" src="/asw.min.js" defer></script>
<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function(event) {
        var options = {
            version: 1,
            storageName: "offline-cache",
            debug: false,
            filePath: "/asw.min.js",
            scope: "/",
            rules: [
                {
                    conditions: [
                        { url: "*Plugins/MediaDirectory/*.jpg" },
                        { url: "*Plugins/MediaDirectory/*.jpeg" },
                        { url: "*Plugins/MediaDirectory/*.webp" }
                    ],
                    strategy: AdvancedServiceWorker.Strategies.CacheFirst
                },
                {
                    conditions: [
                        { url: "*Plugins/MediaDirectory/*.mp4" },
                        { url: "*Plugins/MediaDirectory/*.webm" }
                    ],
                    strategy: AdvancedServiceWorker.Strategies.NetworkOnly
                },
                {
                    conditions: [
                        { url: "*.png" },
                        { url: "*.jpg" },
                        { url: "*.jpeg" },
                        { url: "*.gif" },
                        { url: "*.webp" },
                        { url: "*.ico" },
                        { url: "*.css" },
                        { url: "*.svg" },
                        { url: "*.svg?*" },
                        { url: "*.css?*" },
                        { url: "*.js" },
                        { url: "*.js?*" }
                    ],
                    strategy: AdvancedServiceWorker.Strategies.Race,
                    networkTimeout: 500,
                },
                {
                    conditions: [
                        { url: "/" },
                        { url: "/Video/*" },
                        { url: "/Tag/*" },
                        { url: "/Videos*" },
                        { url: "/Player*" }
                    ],
                    strategy: AdvancedServiceWorker.Strategies.Race,
                    offline: "/Offline",
                    networkTimeout: 3000,
                },
                {
                    conditions: [
                        { url: "*" }
                    ],
                    strategy: AdvancedServiceWorker.Strategies.Race,
                    offline: "/Offline",
                    networkTimeout: 1000,
                }
            ]
        };

        var serviceWorker = new AdvancedServiceWorker.Controller(options);
        serviceWorker.ensureInstalled();
    });
</script>

About

A customizable and dynamic, yet simple service worker for your website

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published